Question
First Question /** * TimeSlots can be of 15 minutes, 30 minutes, 45 minutes and 1 hour duration. * You may assume startTime is already
First Question
/**
* TimeSlots can be of 15 minutes, 30 minutes, 45 minutes and 1 hour duration.
* You may assume startTime is already set and is in multiples of 15 minutes.
* if endTime is more than 60 minutes away from startTime, set endTime to 60 minutes
* after startTime
* if endTime is less than 15 minutes away from startTime (or for that matter, before startTime),
* set endTime to 15 minutes after startTime
* in all other cases, set endTime to passed time.
* @param endTime
*/
public void setEndTime(Time endTime) {
//TO BE COMPLETED
}
Second Question
/**
*
* @param other
* @return true if there is any overlap between calling object and parameter object, false otherwise
* For example,
* there is an overlap between slot (12:00-12:30) and slot (12:15-13:00)
* there is an overlap between slot (12:00-12:30) and slot (11:15-12:45)
* there is an overlap between slot (12:00-12:30) and slot (11:15-12:15)
* there is an no overlap between slot (12:00-12:30) and slot (12:30-13:00)
*
*/
public boolean overlapsWith(TimeSlot other) {
return false; //TO BE COMPLETED
}
}
----------Here is my time class.
package option1.stage1;
public class Time {
private int hour, minute;
public Time(int hour, int minute) {
setHour(hour);
setMinute(minute);
}
public Time(Time t) {
setHour(t.hour);
setMinute(t.minute);
}
public Time() {
setHour(0);
setMinute(0);
}
public int getHour() {
return hour;
}
public void setHour(int hour) {
hour = hour%24;
this.hour = hour;
}
public int getMinute() {
return minute;
}
/**
*
* @param minute
*/
public void setMinute(int minute) {
if(minute >= 45)
this.minute = 45;
else if(minute >= 30)
this.minute = 30;
else if(minute >= 15)
this.minute = 15;
else
this.minute = 0;
}
public String toString() {
if(hour < 10 && minute < 10)
return "0"+hour+":0"+minute;
if(hour < 10)
return "0"+hour+":"+minute;
if(minute < 10)
return hour+":0"+minute;
return hour+":"+minute;
}
public boolean equals(Object other) {
if(other instanceof Time)
return hour == ((Time)other).hour && minute == ((Time)other).minute;
else
return false;
}
/**
*
* @param other
* @return the difference in minutes between calling object and other object.
* note that the value returned will be positive if calling object comes after
* parameter object and negative if calling object comes before parameter object.
* for example,
* if calling object represents 14:00 and parameter represents 12:30, return 90.
* if calling object represents 13:00 and parameter represents 17:30, return -270.
*/
public int diff(Time other) {
return(this.getHour()*60 + this.getMinute())-(other.getHour()*60 + other.getMinute()); //TO BE COMPLETED
}
/**
* @param other: object against which calling object should be compared
* @return 1 if calling object is after parameter object
* -1 if calling object is before parameter object
* 0 if calling object and parameter object are at the same time
*/
public int compareTo(Time other) {
int difference=this.diff(other);
if(difference>0)
return 1;
else if(difference<0)
return -1;
else
return 0;
//TO BE COMPLETED
}
/**
*
* @param quarterHourCount (assumed to be non-negative).
* @return a Time object that represents the calling object shifted forward by
* quarterHourCount increments of 15 minutes.
* for example,
* if calling object represents 14:30 and quarterHourCount = 5,
* return Time object representing 15:45.
*/
public Time advance(int quarterHourCount) {
Time a =new Time(hour,minute);
for(int x =1; x<= quarterHourCount;x++) {
a.minute +=15;
if(a.minute== 60)
{
a.minute = 0;
a.hour++;
if(a.hour == 24)
a.hour=0;
}
}
return a;
//TO BE COMPLETED
}
}
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