Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider a Time class that represents a point in time, such as 9 a . m . or 3 : 3 0 p . m

Consider a Time class that represents a point in time, such as 9 a.m. or 3:30 p.m. Complete the implementation of the following two constructors for the Time class in which the time is stored as an integer that represents the number of minutes since midnight. public class Time
{
private int minutesSinceMidnight;
/**
Initializes a Time object to represent midnight.
*/
public Time()
{
/* Your code goes here */
}
/**
Initializes a Time object to represent the given time.
@param hours the hours component of the time: 0-12
@param minutes the minutes component of the time: 0-59
@param period a string indicating the period of the day: "am" or "pm"
*/
public Time(int hours, int minutes, String period)
{
/* Your code goes here */
}
/**
Returns the hour component of the time.
@return the hours as a value between 0-12
*/
public int getHours()
{
int hours = minutesSinceMidnight /60;
if (hours >12){ hours = hours -12; }
else if (hours ==0){ hours =12; }
return hours;
}
/**
Returns the minutes component of the time.
@return minutes as a value between 0-59
*/
public int getMinutes()
{
return minutesSinceMidnight %60;
}
/**
Return the period of the day.
@return a String indicating "am","pm", "noon" or "midnight"
*/
public String getPeriod()
{
if (minutesSinceMidnight ==0){ return "midnight"; }
else if (minutesSinceMidnight ==720){ return "noon"; }
if (minutesSinceMidnight <720){ return "am"; }
else { return "pm"; }
}
}

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

Icdt 88 2nd International Conference On Database Theory Bruges Belgium August 31 September 2 1988 Proceedings Lncs 326

Authors: Marc Gyssens ,Jan Paredaens ,Dirk Van Gucht

1st Edition

3540501711, 978-3540501718

More Books

Students also viewed these Databases questions