Question: Java // Write a class to // You need to be able // as be able to 77 2 minutes and 59 represent a duration

Java
 Java // Write a class to // You need to be

// Write a class to // You need to be able // as be able to 77 2 minutes and 59 represent a duration of time in minutes and seconds. to non-destructively add two time objects as well structively advance a time by one second (so, for example, seconds becomes 3 minutes). You will also Your class should work with my test function when uncomin will also need impleme // eheed to implement a compareTo function to compare two time // values (e.g. minut // : 1 minute and 40 seconds is less than 2 minutes and 10 seconds). Right now the class skele ton is commented out because it won't compite: // Math hi // but you want the total to.bel minute and 30seconds: 90/60-1 and 90%60-39 nts: say you add 50 seconds and 40 seconds, the total is 90 seconds, class time implements Comparablectime> public static void test() time t1 = new time (2,40); // 2 minutes and 40 seconds time t2 new time(1,19); // 1 minute and 19 seconds time t3 t1.add (t2); System.out.println(t3); 1/ should print "3 min 59 sec" t3.tick(): // destructively advance t3 by one second System.out.println(t3); // should now print "4 min sec" System.out.println(t1.add(new time (1,30)));/1 prints "4 min 10 sec" System.out.println(t1.compareTo(t2)); // should print a positive int // add t1 and t2 times non-destructively I/test // you need to complete the rest of the class so that test() will work //time class

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!