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 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
Step 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