Question: Code: /** * Clock class */ public class Clock{ private int hours,minutes,seconds; public Clock(){ hours = minutes = seconds = 0; } public Clock(int h,

 Code: /** * Clock class */ public class Clock{ private inthours,minutes,seconds; public Clock(){ hours = minutes = seconds = 0; } publicClock(int h, int m, int s){ validate(h,m,s); } public void setHours(int h){validate(h,minutes,seconds); } public void setMinutes(int m){ validate(hours,m,seconds); } public void setSeconds(int s){

Code:

/** * Clock class */ public class Clock{ private int hours,minutes,seconds; public Clock(){ hours = minutes = seconds = 0; }

public Clock(int h, int m, int s){ validate(h,m,s); } public void setHours(int h){ validate(h,minutes,seconds); }

public void setMinutes(int m){ validate(hours,m,seconds); } public void setSeconds(int s){ validate(hours,minutes,s); } public int getHours(){ return hours;} public int getMinutes(){ return minutes;} public int getSeconds(){ return seconds;}

public void tick(){ seconds++; if (seconds > 59){ seconds=0; minutes++; } if (minutes > 59){ minutes=0; hours++; } if (hours > 23) hours = 0; } public boolean equals(Object obj){ if (obj instanceof Clock){ Clock c = (Clock)obj; if (this.getHours()==c.getHours() && this.getMinutes()==c.getMinutes() && this.getSeconds()==c.getSeconds()) return true; } return false; } public String toString(){ return hours+":"+minutes+":"+seconds; } private void validate(int h, int m, int s){ if (h>=0 && h=0 && m=0 && s

Please show work and final output display.

Objective: Interfaces and Algorithm Performance 1. Consider the Clock class, demonstrated previously in lecture (and available on D2L) that allows the representation of a time with hours(0-23), minutes(0-59) and seconds(0-59) components that are provided through an appropriate constructor Have this class implement the Comparable interface. When comparing Clock objects, you must use chronological order 2. Create a Driver class that implements the following methods with the headers below: ublic static void insertionSort (Comparablel c) public static void selectionSort (Comparable[ c) 3. Have the main method in your Driver class create an array of Clock objects that has a "large" size. You should randomly generate the three components for each Clock object but reject those combinations where any component is not within its specified range 4. Then have the main method in your Driver class sort this array of Clock objects using both the insertionSort and selectionSort methods you wrote, timing how long each run takes. You will have to insert appropriate timing code into your program (use System.nanoTime() or System.currentTimeMillis()) and you will also have to experiment with the "large" array size to see any meaningful results when sorting. 5. Specifically, run your code on the teaching lab computers and answer the following a. What is the largest array size that can be sorted in less than 2 seconds with b. What is the largest array size that can be sorted in less than 2 seconds with questions, putting your answers in COMMENTS at the top of your Driver class code insertion sort? selection sort

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!