Java Hi, I\'m making a Lottery simulator and really need help as I am VERY new t
ID: 3875773 • Letter: J
Question
Java
Hi, I'm making a Lottery simulator and really need help as I am VERY new to java. We are supposed to use Arrays and Array Lists
Hi, I would like to make a Java lottery simulator. This one is different than most, however. The program requirements are:
1) The patron enters his/her 6 chosen numbers (from the numbers 1 through 42 without duplicates) on the keyboard at the appropriate prompt(s). This same, single set of numbers will be used as the patron’s numbers throughout this simulation. It is as if the patron plays the same numbers every week (Jack tells us that this is a common occurrence). We will be testing this set of numbers against a year’s worth of computer-generated picks.
2) For each lottery drawing (52 weeks with 2 drawings a week) in your simulation, the computer must randomly pick and display an initial 6 numbers followed by a 7th number, called the bonus number. The possible random numbers (integers) are 1 through 42. You may not have duplicates!
3) Test the lottery drawing numbers against the patron's choices for the prize winnings, cumalative frequencies(Showing how many times each of the paterons choices were drawn throughout the year) and display each of the lottery drawings for a year along with the cumlative frequency of jackpot winnings. For example if the patrons's choice are 1-35-3-4-12-6 and the drawings are 12-3-4-35-1-6 and a bonus of 18 the program should print the lottery drawings (including the bonus number) along with a message that the patron won the jackpot (order does not matter). The bonus number is not included for the jackpot prize. The count of the number of jackpots should be incremented along with the number of times the computers chocies match (frequency of 1's,2's,etc) At the end of the year report the total count of jackpots won (if none report 0) along with the frequencies for each of the patron's chosen numbers
4.) Use two classes a driver and tester and a lottery drawing data type. The driver and tester class get the patrons choices,loops through a years worth of lottery drawings and prints the resulting statistics. The lottery drawing class should have a constructor that creates the random lottery drawing (without duplicates) when the class is instaniated, storing the numbers in private ArrayList. Class data should also include a private static array of ints as frequencies counting the occurrences of (at least) the patron's choices, and private static counters for the number of jackpots won. Among the methods for the lottery drawing class include: a method to update the frequencies , a method test for winnings, static method(s) to print the static data that records the frequencies and winnings, and overrride the toString method to print the ArrayList and identify the bonus number. Be sure that the bonus number can be viewed and tested seperatly from the first 6 numbers since its not included in the big jackpot winnings.
5.) Use Math.random for all number generation, and use an ArrayList for both the lottery drawings and patrons choices. Your ArrayList needs to specify an apporpriate data type. You must also use one "regular" array (holding its) to accumulate/count frequencies of the patron's numbers throughout the year. It must reflect a modular design using multiple methods
6.) Allow the patron to choose to have the computer pick the patrons numbers to simulate the patrons EasyPick option. Display These number and use them as said. (Avoid duplicates)
THANK YOU!
Explanation / Answer
import java.util.Random;
import java.util.Scanner;
public class Main {
private static float totalWinnings = 0;
private static int[] numbers = new int[6];
private static int[] draw = new int[6];
private static int totalMatches;
private static int numberOfGames = 100;
public static void main(String[] args){
//draw the numbers
simulateGames();
//print to the console
if(totalWinnings > 0)
System.out.println("You won £"+totalWinnings+"0");
else
System.out.println("You didn't win anything.");
}
private static void selectNumbers(){
//indicate the user to enter their numbers
System.out.println("Please enter your 6 numbers between 1 and 49:");
//loop until 6 numbers have been chosen
for(int i = 0; i < numbers.length; i++){
Scanner s = new Scanner(System.in);
int number = s.nextInt();
numbers[i] = number;
}
}
private static void draw(){
for(int i = 0; i < draw.length; i++){
int number = new Random().nextInt(49);
if(number == 0){
while(number == 0)
number = new Random().nextInt(49);
} draw[i] = number;
}
}
private static int findMatches(int[] chosen, int[] draw){
//loop through chosen numbers and see if they exist in the draw
int matches = 0;
for(int i = 0; i < chosen.length; i++){
for(int x = 0; x < draw.length; x++){
if(draw[x] == chosen[i]){
matches++;
}
}
} return matches;
}
private static void simulateGames(){
//select the numbers
selectNumbers();
//loop through the games
for(int i = 0; i < numberOfGames; i++){
draw();
totalMatches = findMatches(numbers, draw);
int money = 0;
switch(totalMatches){
case 0:
money = 0; break;
case 1:
money = 0; break;
case 2:
money = 0; break;
case 3:
money = 10; break;
case 4:
money = 50; break;
case 5:
money = 250; break;
case 6:
money = 1500000; break;
default:
money = 0;
} totalWinnings += (float)money;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.