Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

a. Describe the encounter. What made it intercultural?

Answered: 1 week ago