Question
JAVA CODE TOPIC ABSTRACT DATA TYPES We are creating an ADT called Time to represent a time of day( the time that youd see on
JAVA CODE TOPIC ABSTRACT DATA TYPES
We are creating an ADT called Time to represent a time of day( the time that youd see on a clock on the wall). Don't bother with date or day of the week. Time has an hour component, a minute component, and an AM/PM designation. Think about designing this data type in two different ways. ADT is defined by what the operations are that it can do, and not how it does those operations. Assume the operations are:
- Get the hour, minute and AM/PM components of the time.
- Compare this Time against otherTime to figure out which one is sooner in the day (a day starts at 12AM [midnight] and ends at 11:59PM).
-Get the difference in minutes between this Time and otherTime. (as in the difference between 3PM and 3:30PM results in 30 minutes).
For instance, the public methods of this class might look like the code below (method bodies omitted).
public class Time {
public int getHour() { } public int getMin() { } public String getAMorPM() { }
/** Return +1 if time is after otherTime, -1 if time is before otherTime, and 0 if the times are the same. */
int compareTo(Time otherTime) { }
int differenceInMin(Time otherTime) { } }
(a) Take note that the Time class above is does not have instance variables/fields. Describe TWO different ways of implementing this ADT in terms of what private instance variables (and corresponding data types) you would use to implement the Time class. There are plenty of different ways possible. Pick one that makes certain operations easier or more straightforward to implement, and then pick another that makes a different group of operations easier to implement.
(b) For each of the implementations, describe how you would implement the five methods written above. Write JAVA code or an explanation by writing a sentence or two for each operation. And then contrast and compare your two implementations in terms of which operations are easier or more forward to implement in one of the designs, and which are easier or more forward to implement in the other.
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