Create a weekly lottery program Generate five distinct rando

Create a weekly lottery program.

Generate five distinct random numbers between 1 and 40 (inclusive) and stores them in an array named randNum.

Sort the array containing the lottery numbers.

Prompt the player to select five distinct integers between 1 and 40 (inclusive) and store the numbers in an array named userNum. Allow the player to select the numbers in any order, and the userNum array need not be sorted (you can simply compare each userNum to each element of the randNum array.)

**Make sure that you code the program to compare the user numbers to all of the random generated numbers since the userNum array does not need to be sorted.

For example: If the userNum array holds 5, 25, 15, 40, 35 (not sorted) and the randNum array holds 5, 15, 25, 35, and 40 (sorted), the user won.

Determine whether the player guessed the lottery numbers correctly. If the player guessed the lottery numbers correctly, display the message \"You win!\"; otherwise display the message \"You lose!\" and the correct lottery numbers from the randNum array.

Your program should allow a player to play the game as many times as they player wants to play. Before each play, generate a new set of lottery numbers.

Any help would be great thanks in advance, can\'t look like any other program either sadly.

Thanks In Advance.

Solution

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

class DemoReg {
   public static void main(String args[]){
       Random r = new Random();
      
       int Low = 1;
       int High = 40;
   int Result = 0 ;
   int k ;
   List randNum = new ArrayList() ;
   List userNum = new ArrayList() ;
   String c= \"N\";
   do{
       for(int i=0; i <5 ; i++)
           {

// random numbers generation
           randNum.add(r.nextInt(High-Low) + Low);
   }
       System.out.println(randNum);

// sorting random numbers
       Collections.sort(randNum);
   System.out.println(randNum);
   Scanner s=new Scanner(System.in);

System.out.println(\"Enter the elements\");

// taking input from user

for(int i=0;i<5;i++){
   userNum.add(s.nextInt());
   }

//comparing random numbers with user input
if(randNum.equals(userNum) == true){
   System.out.println(\"You win!\");
}else{
   System.out.println(\"You lose!\");
}
System.out.println(\"Would you like to continue\");
c = s.next();
   } while(c == \"Y\");
}
       }

Create a weekly lottery program. Generate five distinct random numbers between 1 and 40 (inclusive) and stores them in an array named randNum. Sort the array co
Create a weekly lottery program. Generate five distinct random numbers between 1 and 40 (inclusive) and stores them in an array named randNum. Sort the array co

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site