that code will not work, unless the user actually picks the numbers in the EXACT order that it is randomized.
and also, most of the code is not even inside of a method, its just ...there.
your method getRandomNumber is good, except it could be written cleaner.
i will post correction
Compiles, not tested.
import java.util.Scanner;
import java.util.Random;
public class Lotto
{
int[] randomNum;
int[] userGuess;
public static void main (String[] args)
{
getRandomNumbers();
getUserNumbers();
announceReward();
}
public void getRandomNumbers()
{
int min=1;
int max=60;
Random randGenerator= new Random();
randomNum = new int[7];
//we create 7 random numbers and store them inside an array
for(int i=0;i<randomNum.length;++i)
{
randomNum[i] = randGenerator.nextInt(max-min+1) + min;
}
}
//ask user for guess//
//we can loop this around 7 times since it is identical code...AGAIN storing numbers in an array.
//Another correction, it is placed inside its own method. (getUserNumbers)
public void getUserNumbers()
{
int[] userGuess = new int[7];
Scanner input=new Scanner(System.in);
for(int j=0;j<7;++j)
{
System.out.println(j+") Please enter a number between one and sixty:");
//preview: 1) Please enter a number between one and sixty:
userGuess[j]=input.nextInt();
}
}
// the string arrays//
//Code previously written did not work because it only checked
// the First guess with the First random number, and the 2nd guess with the 2nd random...it did not check every possible case... for example the 1st guess with 4th random.
private boolean checkSingleNumberForWinner(int guess)
{
//This method checks a single number to see if it is one of the guesses, if it is..the method returns TRUE.
//if not, it returns false
for(int i=0;i<randomNum.length;++i)
{
if(guess == randomNum[i])
return true;
}
return false;
}
public void announceReward()
{
//correction from original code, array only needs 1 set of {}.
String[] jackpot={"There is an empty feeling in your stomach.","You get a quarter!", "You receive a coupon with thirty-five cents off your next purchase when you spend five dollars.",
"You get a dollar.", "You get hundred dollars!", "You get five thousand dollars!", "You\'ve just won a million dollars!!!!!!!!!!"};
if(userGuess.length > jackpot.length)
return;
//the above line is to make sure there is less guesses than there is prizes.
//this for loop will check all our guesses for winners, and add them up.
int wins=0;
for(int i=0;i<userGuess.length;++i)
{
if(checkSingleNumberForWinner(userGuess[i]))
++wins;
}
System.out.println(jackpot[wins]);
}
}