Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part A: Create a new version of the LotteryTicket class and Call this new class ComparableTicket. This new class must implement the Comparable interface, which

Part A:

Create a new version of the LotteryTicket class and Call this new class ComparableTicket. This new class must implement the Comparable interface, which means you have to add a compareTo() method. Two lottery tickets are considered equal if they have the same ticket id. Otherwise, the ticket with the lower ticket id value is considered to be "less than" the other ticket. Also, modify the ComparableTicket constructor to use the IntSort class to sort the six numbers on each new ticket into ascending order. Create a new version of the LotteryDraw class and call this new class ComparableDraw. Change the type of tickets held by the draw from LotteryTicket to ComparableTicket. Also, add two accessor methods: a getTickets() method that returns a reference to the array of tickets; and a getTicketQuantity() method that returns the draw's ticketQty value. Then, write a Sorter class containing a single method called selectionSort(). This method accepts a partially-filled array of Comparable objects and an integer that indicates how many objects are in the array. Use the selection sort algorithm to sort the objects in the array. This means that this selection sort algorithm can be coded in two ways: 1. With each pass, find the smallest element and swap it with the element at the beginning of the unsorted portion of the array; or 2. With each pass, find the largest element and swap it with the element at the end of the unsorted portion of the array. Use the second approach for your Sorter class.

Then, modify the LotteryDrawTest class to produce a new version called ComparableDrawTest. Change all mentions of LotteryTicket to ComparableTicket, and all mentions of LotteryDraw to ComparableDraw. Create a ComparableDraw object that can hold up to 20 tickets, and loop to add 10 ComparableTicket objects to the draw. This time, however, generates random ticket id values between 1000 and 9999. This means the tickets in the draw will not initially be sorted by ticket id. Create the display showing the winning numbers, followed by a list of the unsorted tickets, the number of matches each ticket has the winning numbers, and the dollar prize amount for which each ticket is eligible. Use your selectionSort() method to sort the draw's array of tickets. Use the getTickets() and getTicketQuantity() methods from the ComparableDraw class to help accomplish this task. Then repeat the same display of tickets, which should now be sorted in ascending order according to their ticket id values. image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedPart B:

Create a new class called TimeTest with a main() method that performs the following testing. Use a for loop to test each quantity starting with 0 and incrementing by 10,000 up to 100,000. For each quantity value: Construct a new ComparableDraw instance that can hold that quantity of ComparableTicket objects; Fill the draw with that quantity of tickets. Randomly generate the ticket id values as described in Part A which means those values will be unsorted; Use your selectionSort() method to sort the tickets; Immediately before and after sorting, use System.currentTimeMillis() to capture the current system time on your computer. Subtract the "before" time from the "after" time to get the duration that it took to perform the sort operation (a number of milliseconds); and Display the quantity and duration. To align the columns as shown, try using the Java printf command, similar to the following line from my sample solution for this assignment: System.out.printf("%6d%12d ", qty, duration); A String like "%6d%12d " is how we can instruct Java on how to display the two values that follow (qty and duration). %6d directs Java to display the numeric value of qty right justified with a width of 6 characters. The d stands for the somewhat old-fashioned term "decimal". Similarly, %12d directs Java to display the numeric value of duration right-justified with a width of 12 characters. " " is, of course, Java's newline character.

image text in transcribed

The output from executing ComparableDrawTest must be in the same format as the sample output shown below (except your randomly generated numbers will be different). Notice that the six numbers for each ticket are sorted, as are the six winning numbers. The output from executing your TimeTest class should look similar to the following example

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Uropean Conference Adbis 2020 Lyon France August 25 27 2020 Proceedings Lncs 12245

Authors: Jerome Darmont ,Boris Novikov ,Robert Wrembel

1st Edition

3030548317, 978-3030548315

More Books

Students also viewed these Databases questions

Question

What are the best practices for managing a large software project?

Answered: 1 week ago

Question

4. What advice would you give to Carol Sullivan-Diaz?

Answered: 1 week ago