import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main
(String[] args
){
int input; //Holds keyboard input
final int TOTAL_ANSWERS = 10; //Number of answers
int[] guesses = new int[TOTAL_ANSWERS]; //Array to hold answers
//Creates a Scanner object for keyboard input
Scanner userInput
= new Scanner
(System.
in);
//Gets the users Input
System.
out.
println("Welcome to the Lottery!");
for(int i = 0; i < guesses.length; i++)
{
System.
out.
print("Enter digit " + (i
+1) + ": "); input = userInput.nextInt();
while(!validate(input))
{
System.
out.
println("Invalid input. Please enter a digit between 1-9"); System.
out.
print("Enter digit " + (i
+1) + ": "); input = userInput.nextInt();
}
guesses[i] = input;
}
//Creates a Lottery Object
TestingClass myLottery = new TestingClass(guesses);
System.
out.
print("\nCorrect Numbers: " + (myLottery.
totalCorrect()));
}//End of Main Method
public static boolean validate(int a)
{
boolean status;
if( a == 1 || a == 2 || a == 3 || a == 4 || a == 5 || a == 6 || a == 7 || a == 8 || a == 9)
status = true;
else
status = false;
return status;
}
}//End of TestingClassDemo
class TestingClass {
private int[] lotteryNumbers = new int[10];{
for(int i = 0;i < lotteryNumbers.length ;i++)
{
lotteryNumbers
[i
] = (int) (Math.
random()*10); System.
out.
print(lotteryNumbers
[i
]+ " "); }
}//End of LOOP
//Creates a Private Array for lotteryNumbers the user Guesses
private int[] lotteryGuesses = new int[10];
//Creates a Private int totalCorrect whether correct guesses are stored
private int totalCorrect = 0;
//Appends lotteryGuesses to lotteryNumbers for comparison
public TestingClass(int[] lotteryNumbers)
{
lotteryGuesses = lotteryNumbers;
}
/** Compares whether the uses LotteryGuess are correct
and if they are increases total Correct
*/
public int totalCorrect()
{
for( int x = 0; x < lotteryNumbers.length; x++)
{
if(lotteryGuesses[x] == lotteryNumbers[x])
{
totalCorrect += 1;
}
}
return totalCorrect;
}
}//End of Public Class TestingClass