You will create a new program that simulates the game of Lotto. How does this wo
ID: 3690099 • Letter: Y
Question
You will create a new program that simulates the game of Lotto. How does this work? The user will input 6 numbers (integer): ranging from 1 to 59. The computer will randomly pick the winning numbers (6 of them and one "Bonus number). In order to win first prize, the user must match all of the 6 numbers. In order to win second prize, the user must match 5 of the 6 numbers AND the Bonus number. Numbers CANNO T be generated twice. For example, 6, 18, 18, 50, 52, 55 is not valid; as 18 middot appears twice. Winning numbers (via the computer) arc always presented in ascending order. This lab MUST use Arrays for storing the numbers. Include data validation and echo user input!!!!! Fifteen points (15) will be deducted if the Java Source code has been modified and recompiled. In addition to solving the programming challenge, remember to include the internal documentation.Explanation / Answer
import java.util.Random;
import java.util.Scanner;
public class Lotto {
//Pick 6 numbers from 1 to 100
//If all of your numbers gets called out, you win
public static void wait (int n) {
long t0,t1;
t0=System.currentTimeMillis();
do{
t1=System.currentTimeMillis();
}
while (t1-t0<1000);
}
public static void main(String[] args) {
Random rand = new Random();
Scanner numScan1 = new Scanner(System.in);
Scanner numScan2 = new Scanner(System.in);
Scanner numScan3 = new Scanner(System.in);
Scanner numScan4 = new Scanner(System.in);
Scanner numScan5 = new Scanner(System.in);
Scanner numScan6 = new Scanner(System.in);
boolean num1Cor = false;
boolean num2Cor = false;
boolean num3Cor = false;
boolean num4Cor = false;
boolean num5Cor = false;
boolean num6Cor = false;
System.out.print("Pick 6 numbers from 0 to 25. Pick your first number: ");
int num1 = numScan1.nextInt();
System.out.println();
System.out.print("Pick your second number: ");
int num2 = numScan2.nextInt();
System.out.println();
System.out.print("Pick your third number: ");
int num3 = numScan3.nextInt();
System.out.println();
System.out.print("Pick your fourth number: ");
int num4 = numScan4.nextInt();
System.out.println();
System.out.print("Pick your fifth number: ");
int num5 = numScan5.nextInt();
System.out.println();
System.out.print("Pick your final number: ");
int num6 = numScan6.nextInt();
System.out.println("Numbers will now start to be drawn, if all of your numbers are called, you win.");
while (true) {
int random = rand.nextInt(25);
System.out.println("Number " + random + ".");
if (random == num1) {
num1Cor = true;
System.out.println("Your number, " + num1 + ", has been called.");
}
else if (random == num2) {
num2Cor = true;
System.out.println("Your number, " + num2 + ", has been called.");
}
else if (random == num3) {
num3Cor = true;
System.out.println("Your number, " + num3 + ", has been called.");
}
else if (random == num4) {
num4Cor = true;
System.out.println("Your number, " + num4 + ", has been called.");
}
else if (random == num5) {
num5Cor = true;
System.out.println("Your number, " + num5 + ", has been called.");
}
else if (random == num6) {
num6Cor = true;
System.out.println("Your number, " + num6 + ", has been called.");
}
if (num1Cor == true && num2Cor == true && num3Cor == true && num4Cor == true && num5Cor == true && num6Cor == true) {
System.out.println("You win!!");
break;
}
wait(100);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.