Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4. (a) English The following interface describes a time hh :mm:ss with hours (in range to,23]), mi- nutes (range [0,59]), and seconds (range [o,59]). iass

image text in transcribed
4. (a) English The following interface describes a time hh :mm:ss with hours (in range to,23]), mi- nutes (range [0,59]), and seconds (range [o,59]). iass public interface Time f public void setHour (int h): public void setX inute(int m); public void setSecond (int s) public int getHour ); public int getMinute; public int getSecond) public boolean isBefore(Time t); public String toString English You should write down the Java code for a class MyTime that implements the Time interface. Using your class it should be possible to execute this code with the expected result Tino T1 new MyTise (11,23,56); Syst.em.out.printin("T1 T1.toStringO) // Prints "T1 11:23:56 Time T2 new MyTime) T2.setHour (11); T2.setMinute (33) T2.setSecond (16); System.out.println( T2T2.toString)) 11 Prints "T2- 11:33:16" System.out.printin("T2 Kinutes: " T2.getMinuteO I/ Prints "T2 Minutes: 33" if T1.1sBefore(T2)) System.out.printin("T1 happens before T2"); // Will be printed Time T3 nev MyTise (24,25,26); // Throws a RuntimeException // since 24 is not a valid hour Notice An exception of type RuntimeException should be raised if a time value hh:mm:ss is not valid (not within the given ranges). The class should be encapsulated and follow good Java coding practise The class should (of course) work for all possible valid times

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

More Books

Students also viewed these Databases questions