Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

What about leadership lessons from particularly good or bad bosses?

Answered: 1 week ago

Question

When would you use one approach, and when would you use another?

Answered: 1 week ago