- This event has passed.
7 PM – Intro to Java – Roland
April 10 @ 7:00 pm - 8:00 pm
Today We Did
- Warm-Up Review
- While Loop Problem
- For Loop & Lists Problem
- Random (Feel free to explore the documentation here!: https://docs.oracle.com/javase/8/docs/api/java/util/Random.html)
- Random r = new Random();
- r.nextInt(lower_bound, upper_bound) or r.nextInt(upper_bound)
- Arrays.asList(…);
- AYCLOGIC Adventure Game!
- Used random to create a game where the player has to fight as many animals as they can from the list without losing all their health (see the notes folder for the completed program)
Homework
- Create a new Java file April10_RandomHW.java and create the Magic 8 Ball program below
- Create a forever loop and inside the loop do the following:
- Ask user “Enter yes or no question.” and take user input and save/set user input into a variable called “user_question”.
- If user input is “quit”, print “Bye bye” and break from the While Loop.
- Generate random number between 1 to 8
- to generate random number between 1 to 8 and save/set random number into variable called “randomInt”.
- Inside the while loop print to the screen according to “randomInt”
- If randomInt is equal to 1, print “It is certain.”
- If randomInt is equal to 2, print “Most likely.”
- If randomInt is equal to 3, print “Signs point to yes.”
- If randomInt is equal to 4, print “I don’t think so.”
- If randomInt is equal to 5, print “Ask again later.”
- If randomInt is equal to 6, print “Concentrate and ask again.”
- If randomInt is equal to 7, print “Outlook not so good.”
- If randomInt is equal to 8, print “My reply is no.”
- After printing the answer, go back to Step 1 (Ask user “Enter yes or no question”) until user input “quit”.
- Make sure you use r.nextInt() to get the random number!!!
- Create a forever loop and inside the loop do the following:
- 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 (April10_Random.java): https://drive.google.com/drive/folders/10JdSDu9bC5k_Jewi3BxazkkuBNrrVpqA?usp=sharing