American Young Coder (AYC)

AYC logo
Loading Events

« All Events

  • This event has passed.

7 PM – Intro to Java – Roland

April 10 @ 7:00 pm - 8:00 pm

Today We Did
  1. Warm-Up Review
    1. While Loop Problem
    2. For Loop & Lists Problem
  2. Random (Feel free to explore the documentation here!: https://docs.oracle.com/javase/8/docs/api/java/util/Random.html)
    1. Random r = new Random();
    2. r.nextInt(lower_bound, upper_bound) or r.nextInt(upper_bound)
    3. Arrays.asList(…);
  3. AYCLOGIC Adventure Game!
    1. 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
  1. Create a new Java file April10_RandomHW.java and create the Magic 8 Ball program below
    1. Create a forever loop and inside the loop do the following:
      1. Ask user “Enter yes or no question.” and take user input and save/set user input into a variable called “user_question”.
      2. If user input is “quit”, print “Bye bye” and break from the While Loop.
      3. Generate random number between 1 to 8
        1. to generate random number between 1 to 8 and save/set random number into variable called “randomInt”.
      4. Inside the while loop print to the screen according to “randomInt”
        1. If randomInt is equal to 1, print “It is certain.”
        2. If randomInt is equal to 2, print “Most likely.”
        3. If randomInt is equal to 3, print “Signs point to yes.”
        4. If randomInt is equal to 4, print “I don’t think so.”
        5. If randomInt is equal to 5, print “Ask again later.”
        6. If randomInt is equal to 6, print “Concentrate and ask again.”
        7. If randomInt is equal to 7, print “Outlook not so good.”
        8. If randomInt is equal to 8, print “My reply is no.”
      5. After printing the answer, go back to Step 1 (Ask user “Enter yes or no question”) until user input “quit”.
    2. Make sure you use r.nextInt() to get the random number!!!
  2. 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

Details

Date:
April 10
Time:
7:00 pm - 8:00 pm
Verified by MonsterInsights