American Young Coder

AYC logo
Loading Events

« All Events

  • This event has passed.

3 PM – Intro to Java

October 31, 2020 @ 3:00 pm - 4:00 pm

  1. Homework:
    1. Last week in the class, we did tell me your age program. Change the program so it will continuously ask user about his/her age until the user enter “quit” or “exit”
    2. Create “Magic 8 Ball” game according to the following instructions
      1. For you to be able to create above game, you need to know how to select a random number in Java. Below is the example of code how to do it
      2. Create a new Java file GenerateRandom.java in your IntelliJ
      3. Copy and paste below code and run below code couple of times and you will see that it will print a different number between 0 to 24 every time you run.

        import java.util.Random;
        public class GenerateRandom {
            public static void main( String args[] ) {
              Random rand = new Random(); 
              int upperBound = 25;
              //generate random values from 0-24
              int int_random = rand.nextInt(upperBound); 
              System.out.println("My random number is "+int_random);
            }
        }
        
      4. If you want to generate random number between 0 to 8, you need to change below from
        int upperBound = 25;

        into

        int upperBound = 9;
      5. The remaining instructions on how to create the Magic 8 Ball game can be found by clicking here

Details

Date:
October 31, 2020
Time:
3:00 pm - 4:00 pm
Event Category: