Design and implement an ADT diat represents the time of day. Represent the time
ID: 3906832 • Letter: D
Question
Design and implement an ADT diat represents the time of day. Represent the time as hours, minutes, and seconds on a 24-hour clock. The hours, minutes, and seconds are the private data fields of the class that implements the ADT. Include at least two initialization operations: One that provides a default value for the time (midnight, all fields zero), and another that sets the time to a client-sup-plied value. These operations are the class's constructors. Include operations that set the time, increase the time by I second, return the number of seconds between the time and a given dine, increase the present time by a number of minutes, and two operations to display the time in 12-hour and 24-hour notations.Explanation / Answer
public class TimeOfDay { private int hours; private int minutes; private int seconds; public TimeOfDay() { this.hours = 0; this.minutes = 0; this.seconds = 0; } public TimeOfDay(int hours, int minutes, int seconds) { this.hours = hours; this.minutes = minutes; this.seconds = seconds; } public int getHours() { return hours; } public void setHours(int hours) { this.hours = hours; } public int getMinutes() { return minutes; } public void setMinutes(int minutes) { this.minutes = minutes; } public int getSeconds() { return seconds; } public void setSeconds(int seconds) { this.seconds = seconds; } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.