Question
LotteryDemo will include a main method to test the LotteryTicket class. Be sure to include a documentation comment in LotteryDemo that summarizes what the program
LotteryDemo will include a main method to test the LotteryTicket class. Be sure to include a documentation comment in LotteryDemo that summarizes what the program does.
The LotteryTicket class will have a single field, an int array of size 3 to hold a set of selected numbers. The class will have two constructors. The first is a no-args constructor that is used to generate three random numbers in the range of 1-10 to be assigned to each location in the int array. Remember to import the Random class to perform this task. The second is a parameterized constructor that takes three int arguments to be assigned to each location in the int array.
The LotteryTicket class will have a custom equals method that compares the contents of the int array field between two LotteryTicket objects. If all three numbers are equal between the two objects, the method will return true. Otherwise, it will return false.The LotteryTicket class will have a custom toString method.
If the selected numbers for a LotteryTicket object are 1, 2, and 3, the toString method should print the following:
The selected numbers for this lottery ticket are 1, 2, and 3.
In the main method of this program, you will use the Scanner class to accept user input to create a user generated LotteryTicket object. You will also need a second LotteryTicket object that is constructed using the no-args constructor. These randomly generated numbers will be the winning numbers.
Next, ask the user to input three numbers that will be used in a parameterized constructor. You are encouraged to use some additional variable to hold these numbers before constructing thisLotteryTicket object.
After constructing the LotteryTicket object with user input, print that object to the console.Finally, perform a comparison between the two LotteryTicket objects to determine if you won the lottery.
Winning Output Please enter a number for your lottery ticket: 1 Please enter a number for your lottery ticket: 2 Please enter a number for your lottery ticket: 9 The selected numbers for this lottery ticket are 1, 2, and 9. Congratulations! You won the lottery! Losing Output Please enter a number for your lottery ticket: 4 Please enter a number for your lottery ticket: 7 Please enter a number for your lottery ticket: 10 The selected numbers for this lottery ticket are 4, 7, and 10. Sorry, better luck next time. The selected numbers for this lottery ticket are 1, 10, and 4Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started