Question: JAVA Instructions: Modify the following class so that it is immutable. Do this by he mutators, and then rewrite these methods so that instead of
Instructions: Modify the following class so that it is immutable. Do this by he mutators, and then rewrite these methods so that instead of changing the object that invoked the method, they create a new object that reflects the requested change. You only need to rewrite those methods that will have new implementations. Do not change the public interface of the class. A class to keep track of the time of day, to the nearest second. public class TimeOfDay public static final int HOURS_PER DAY 24: public static final int MINUTES_PER HOUR 60; public static final int SECONDS-PER-MINUTE-60; /The hours, minutes, and seconds that have elapsed since midnight. private int hours, minutes, seconds; / Create a new object representing the time of day. @param h the hour @param m the minute @param s the second public TimeOfDay (int h, int m, int s) hours-h; minutesm; seconds = s; /** Get the hour represented by this object. public int getHour (return hours; /** Get the minute represented by this object. @return the hour greturn the minute public int getMinute () (return minutes; ret the second represented by this object. 8return the second lic int getsecond () (return seconds: h /Advance the time by one public TimeofDay tick second seconds++: it (seconds SECONDS PER NINDTE) seconds 0; minutes++: if (minutes NINUTES PER HOUR) minutes 0 hours++ if (hoursBOURS PER DAY) f return this: Advance the time by a nunber of seconds "eparam amount the number of seconds to advance public TimeOfDay advance (int amount) for (int i-l; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
