Please let me know how I can make it better, especially with avoiding repetition without the need to replace the user guesses.
import java.util.Scanner;
public class Lottery {
static int guess[] = new int[3],actual[]= new int[3];
private static void aquireGuess()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Time to play the lottery please choose three numbers ranging from zero to nine.");
System.out.print("Please enter first number:");
guess[0] = keyboard.nextInt();
System.out.print("Please enter second number:");
guess[1] = keyboard.nextInt();
System.out.print("Please enter third number:");
guess[2] = keyboard.nextInt();
keyboard.close();
}
private static void generateLottery()
{
actual[0] = (int)(Math.random()*10);
actual[1] = (int)(Math.random()*10);
actual[2]= (int)(Math.random()*10);
}
private static void compare()
{
if(guess[0]==actual[0]&&guess[1]==actual[1]&&guess[2]==actual[2])
{
System.out.println("Congradulations three matches in exact order!!! You win $1,000,000.");
return;
}
int count = 0;
for(int i=0;i<=2;i++)
{
for(int x=0;x<=2;x++)
{
if (actual[i]==guess[x])
{
count++;
guess[x]=-1;
break;
}
}
}
switch(count)
{
case 0:System.out.println("Sorry better luck next time."); break;
case 1:System.out.println("Good job. One match. You win $10."); break;
case 2:System.out.println("Awsome you made two matches. You win $100."); break;
case 3:System.out.println("Woohoo you matched all three. You win $1,000.");break;
}
}
public static void main(String args[])
{
aquireGuess();
generateLottery();
System.out.println("Your guess were "+guess[0]+" "+guess[1]+" "+guess[2]);
System.out.println("The lottery numbers were "+actual[0]+" "+actual[1]+" "+actual[2]);
compare();
}
}