Question: I have this java program but I need to develop this to match instruction given: Simulate the real lottery MEGA MILLIONS and create a good
I have this java program but I need to develop this to match instruction given:
Simulate the real lottery MEGA MILLIONS and create a good GUI. The rule of the game is (from Internet): The Lottery game in which the ticket purchaser selects, or has the computer randomly assign five (5) different numbers from Field 1 which includes a range of consecutive numbers from one (1) to fifty-six (56) and one (1) number from Field 2 which includes a range of consecutive numbers from one (1) to forty-six (46), shall be called MEGA MILLIONS". For example, the winning numbers from Field 1 may be {03, 05, 10, 20, 43} and from Field 2 {05}. As you can see the number from Field 2 may be the same as one of the numbers of Field 1. You have different ways to develop your algorithm and code. One of the ways is to use ArrayList. You are free to select some other way. Please give UML diagrams for all classes.
import java.util.*; import java.lang.*; import java.io.*; class lottery { public static void main(String[] args) { int[] lottery = new int[5]; int randomNum; for (int i = 0; i < 5; i++) { randomNum = (int) (Math.random() * 56); for (int x = 0; x < i; x++) { if (lottery[x] == randomNum) { randomNum = (int) (Math.random() * 56); x = -1; } } lottery[i] = randomNum; } for (int i = 0; i < lottery.length; i++) System.out.print(lottery[i] + " "); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
