- This event has passed.
7 PM – Intro to Java – Roland
April 3 @ 7:00 pm - 8:00 pm
Today We Did
- For loops
- Looping through lists
- for (datatype var_name : list_name) { }
- for (int i = 0; i < list.size(); i++) { }
- for (int i = list.size() – 1; i >= 0; i–) { }
- Using numbers
- Incrementing forwards
- Incrementing with different values besides 0
- Decrementing/Reverse
- Looping through lists
- While loops
- Using numbers
- Infinite loops asking user for input
- Checking input directly
- True/break
- Boolean flag
- Number 3 GameInventory problem from homework
- https://www.ayclogic.com/java-list-forloop/
- Refer to GameInventory.java in Notes below for final solution
- For loops
Homework
- Create a new Java file April3_LoopHW.java and complete the problems in (https://www.ayclogic.com/java-exercise-while-loop/) (listed below)
- Create a forever loop that will keep asking a user the following question:
- What grade did you get on your Java test?
- If the user answers with a grade that is bigger or equal to 90 then
- print “Good job, you can take a good rest and play your video games all day long”.
- stop the loop.
- If the user answers with a grade that is between 80 to 90 then
- print “Not bad, but I am sure you can do better. Why don’t you study a little bit more and retake the test.”
- If the user answers with a grade that is between 70 to 80 then
- print “I think you need to study a lot harder and retake the test.”
- If the user answers with a grade that is lower than 70 then
- print “All right you are grounded, no video games for 1 year and no computer”.
- stop the loop.
- In the above exercise, you should only stop the loop when the user get above 90 or below 70.
- Create a forever loop that will keep asking a user the following question:
- 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 (April3_Loops.java): https://drive.google.com/drive/folders/10JdSDu9bC5k_Jewi3BxazkkuBNrrVpqA?usp=sharing