Hello folks, first post here and also a Full Time student at the University of Cincinnati. Currently in Programming I which is all Java based. Almost done with the first semester, but I've hit a wall on the current program I'm working on. I'd really appreciate some help with it. Basically, I had to create a lottery program that will generate 5 sets of 5 random numbers, then a set of "winning" numbers. Then those need to be compared to see if any match for a winner.
I've got my program generating the numbers, but I just don't know how to build the proper loop or what I need to do to compare two arrays for common data. I have to print the results for the user. This is also rules for my assignment.
All sets must follow these rules:
1. First number (an integer) must be in the range: 1 to 10, second number: 11 to 20, third number: 21 to 30,
fourth number: 31 to 40, fifth number: 41 to 50.
2. No number can be zero
Winners. Let the player know if they win:
1. 3 numbers match = $100,000
2. 4 numbers match = $250,000
3. 5 numbers match= JACKPOT!! $1,000,000
4. Less than 3 numbers matching, no win.
My code is listed below, any help you all can provide would be greatly appreciated. If my formatting or comments suck, please feel free to let me know. But keep in mind, this is my first semester of programming with no prior experience Thank you!!!
//**************************** // Programmer: Potato McGruff // March 25th, 2013 // University of Cincinnati // Programming I // Auto Lottery Program //**************************** import java.util.Scanner; public class AutoLotto { // Start public class AutoLotto public static void main(String[] args) { // Begin main method. Scanner input = new Scanner(System.in); // Welcome message System.out.println("Welcome to the Auto Lotto, where all your lottery dreams can come true!"); System.out.println("Would you like to try your luck and be our next jackpot winner?"); System.out.print("Press 1 for fun! Press any other number if you're ready to give up! "); int keepPlaying = input.nextInt(); if (keepPlaying == 1) { // start if loop // generating number arrays int[] winningNumbers = {(int)Math.floor(generateRandomNumber()),(int)(Math.floor(generateRandomNumber())+10), (int)(Math.floor(generateRandomNumber())+20), (int)(Math.floor(generateRandomNumber())+ 30), (int)(Math.floor(generateRandomNumber())+ 40)}; int[] numberSetOne = {(int)Math.floor(generateRandomNumber()),(int)(Math.floor(generateRandomNumber())+10), (int)(Math.floor(generateRandomNumber())+20), (int)(Math.floor(generateRandomNumber())+ 30), (int)(Math.floor(generateRandomNumber())+ 40)}; int[] numberSetTwo = {(int)Math.floor(generateRandomNumber()),(int)(Math.floor(generateRandomNumber())+10), (int)(Math.floor(generateRandomNumber())+20), (int)(Math.floor(generateRandomNumber())+ 30), (int)(Math.floor(generateRandomNumber())+ 40)}; int[] numberSetThree = {(int)Math.floor(generateRandomNumber()),(int)(Math.floor(generateRandomNumber())+10), (int)(Math.floor(generateRandomNumber())+20), (int)(Math.floor(generateRandomNumber())+ 30), (int)(Math.floor(generateRandomNumber())+ 40)}; int[] numberSetFour = {(int)Math.floor(generateRandomNumber()),(int)(Math.floor(generateRandomNumber())+10), (int)(Math.floor(generateRandomNumber())+20), (int)(Math.floor(generateRandomNumber())+ 30), (int)(Math.floor(generateRandomNumber())+ 40)}; int[] numberSetFive = {(int)Math.floor(generateRandomNumber()),(int)(Math.floor(generateRandomNumber())+10), (int)(Math.floor(generateRandomNumber())+20), (int)(Math.floor(generateRandomNumber())+ 30), (int)(Math.floor(generateRandomNumber())+ 40)}; // printing sets and winning numbers System.out.println(" Number Set 1 - " + numberSetOne[0] + " " + numberSetOne[1] + " " + numberSetOne[2] + " " + numberSetOne[3] + " " + numberSetOne[4]); System.out.println(" Number Set 2 - " + numberSetTwo[0] + " " + numberSetTwo[1] + " " + numberSetTwo[2] + " " + numberSetTwo[3] + " " + numberSetTwo[4]); System.out.println(" Number Set 3 - " + numberSetThree[0] + " " + numberSetThree[1] + " " + numberSetThree[2] + " " + numberSetThree[3] + " " + numberSetThree[4]); System.out.println(" Number Set 4 - " + numberSetFour[0] + " " + numberSetFour[1] + " " + numberSetFour[2] + " " + numberSetFour[3] + " " + numberSetFour[4]); System.out.println(" Number Set 5 - " + numberSetFive[0] + " " + numberSetFive[1] + " " + numberSetFive[2] + " " + numberSetFive[3] + " " + numberSetFive[4]); System.out.println(""); System.out.println(" Winning Numbers - " + winningNumbers[0] + " " + winningNumbers[1] + " " + winningNumbers[2] + " " + winningNumbers[3] + " " + winningNumbers[4]); } // end if else { // start else System.exit(1); } // end else } // end main method public static double generateRandomNumber() { // begin method generateRandomNumber double x = Math.random()*10+1; return x; } // end generateRandomNumber method } // end public class Auto Lotto