- This event has passed.
3 PM – Intro to Java
October 31, 2020 @ 3:00 pm - 4:00 pm
- Homework:
- 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”
- Create “Magic 8 Ball” game according to the following instructions
- 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
- Create a new Java file GenerateRandom.java in your IntelliJ
- 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); } } - If you want to generate random number between 0 to 8, you need to change below from
int upperBound = 25;
into
int upperBound = 9;
- The remaining instructions on how to create the Magic 8 Ball game can be found by clicking here