- This event has passed.
7 PM – Intro To Java – Roland
March 27 @ 7:00 pm - 8:00 pm
Today We Did
- Learned about &&, ||, !=, and !
- && = And
- || = Or
- != –> not equals (primitives)
- ! –> negate
- .equals() and .equalsIgnoreCase()
- Lists in Java
- List<String> names = new ArrayList<>();
- Adding to a list: names.add(“name”);
- Getting from a list: names.get(0);
- Modifying a list: names.set(0, “new_name”);
- Inserting into a list: names.add(1, “second_name”);
- Size of list: names.size();
- Looping through a list: for (String n: names) {…}
Homework
- Create a new Java file March27_AndOrListHW.java
- Complete the following exercises:
- Write a new Java program that will ask the user for the grade they got on their exam (which is an integer)
- If the number is between 60 to 70, print “Your grade is D”. You have to use AND (&&).
- If the number is between 70 to 80, print “Your grade is C”. You have to use AND (&&).
- If the number is between 80 to 90, print “Your grade is B”. You have to use AND (&&).
- If the number is between 90 to 99, print “Your grade is A”. You have to use AND (&&)
- If the number is equal to 100, print “Your grade is A+, good job”.
- Write a new Java program that will create a List of String and add all of these colors: red, green, blue, purple, yellow, orange. ([“red”, “green”, “blue”, “purple”, “yellow”, “orange”])
- Use for loop to go through each color inside the above list and print all colors to the shell.
- If the color is “blue”, print “blue is my favorite color”. If the color is “yellow”, print “I don’t like yellow color.
- For everything else, just print the color name.
- The result should be like below
red green Blue is my favorite color purple I don't like yellow orange
- Write a new Java program that will ask the user for the grade they got on their exam (which is an integer)
- Upload your answer to google drive before next week Tuesday night.
If you have any questions feel free to email me rolandyang@ayclogic.com
Feel free to reference the code in the notes if you are lost (March27_AndOrList.java): https://drive.google.com/drive/folders/10JdSDu9bC5k_Jewi3BxazkkuBNrrVpqA?usp=sharing