Menu

(Solved) : Information U Need Package Option1stage1 Public Class Time Private Int Hour Minute Public Q32239449 . . .

//the information u need

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 andother object.

* note that the value returned will be positive if callingobject comes after

* parameter object and negative if calling object comes beforeparameter object.

* for example,

* if calling object represents 14:00 and parameter represents12:30, return 90.

* if calling object represents 13:00 and parameter represents17: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 becompared

* @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 sametime

*/

public int compareTo(Time other) {

int difference=this.diff(other);

System.out.println(difference);

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 objectshifted 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 time =new Time(hour,minute);

for(int i =1; i<= quarterHourCount;i++) {

time.minute +=15;

if(time.minute== 60)

{

time.minute = 0;

time.hour++;

if(time.hour == 24)

time.hour=0;

}

}

return time;

//TO BE COMPLETED

}

}

—————

package option1.stage1;

public class Patient {

private String name;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Patient(String name) {

setName(name);

}

public String toString() {

return name;

}

}

———————

package option1.stage2;

import option1.stage1.Time;

public class TimeSlot {

private Time startTime;

private Time endTime;

public Time getStartTime() {

return startTime;

}

public void setStartTime(Time startTime) {

this.startTime = startTime;

}

public Time getEndTime() {

return endTime;

}

/**

* TimeSlots can be of 15 minutes, 30 minutes, 45 minutes and 1hour duration.

* You may assume startTime is already set and is in multiples of15 minutes.

* if endTime is more than 60 minutes away from startTime, setendTime to 60 minutes

* after startTime

* if endTime is less than 15 minutes away from startTime (or forthat 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) {

if (endTime.diff(startTime) < 15) {

endTime = startTime.advance(1);

} else if (endTime.diff(startTime) > 60) {

  

endTime = startTime.advance(4);

}

this.endTime = endTime;

}//TO BE COMPLETED

public TimeSlot(Time startTime, Time endTime) {

setStartTime(startTime);

setEndTime(endTime);

}

public TimeSlot(Time time) {

this.startTime = time;

this.endTime = time;

}

public String toString() {

return startTime+” – “+endTime;

}

/**

*

* @param other

* @return true if there is any overlap between calling objectand 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) {

if (this.startTime.compareTo(other.startTime) > 0 &&this.startTime.compareTo(other.endTime) < 0) {

return true;

}

  

if (this.endTime.compareTo(other.startTime) > 0 &&this.endTime.compareTo(other.endTime) < 0) {

return true;

}

  

if (this.startTime.compareTo(other.endTime) < 0 &&this.endTime.compareTo(other.endTime) > 0) {

return true;

}

  

if (this.startTime.compareTo(other.startTime) < 0 &&this.endTime.compareTo(other.startTime) > 0) {

return true;

}

if (this.startTime.compareTo(other.startTime) == 0 &&this.endTime.compareTo(other.endTime) == 0) {

return true;

}

return false;

}

}

//TO BE COMPLETED

——————————— Here is the question and test( must run pass the test)

package option1.stage3;

import option1.stage1.Doctor;

import option1.stage1.Patient;

import option1.stage2.TimeSlot;

public class Appointment {

private Doctor doctor;

private Patient patient;

private TimeSlot timeSlot;

public Doctor getDoctor() {

return doctor;

}

public void setDoctor(Doctor doctor) {

this.doctor = doctor;

}

public Patient getPatient() {

return patient;

}

public void setPatient(Patient patient) {

this.patient = patient;

}

public TimeSlot getTimeSlot() {

return timeSlot;

}

public void setTimeSlot(TimeSlot timeSlot) {

this.timeSlot = timeSlot;

}

public Appointment(Doctor doctor, Patient patient, TimeSlottimeSlot) {

setDoctor(doctor);

setPatient(patient);

setTimeSlot(timeSlot);

}

public Appointment(Patient patient, TimeSlot timeSlot) {

setDoctor(null);

setPatient(patient);

setTimeSlot(timeSlot);

}

public String toString() {

if(doctor != null)

return patient+” with “+doctor+” for “+timeSlot;

else

return patient+” for “+timeSlot;

}

/**

*

* @param other

* @return true if calling object conflicts with parameterAppointment.

* we say two appointments conflict if they are with the samedoctor

* and the timeSlots overlap.

* HINT: Use method equals from Doctor class and methodoverlapsWith from TimeSlot class

*/

public boolean conflictsWith(Appointment other) {

//TO BE COMPLETED

THERE IS ONLY ONE QUESTION NEED TO ANSWER PLS HELP ME ,TY SOMUCH.

Expert Answer


Answer to Information U Need Package Option1stage1 Public Class Time Private Int Hour Minute Public Q32239449 . . .

OR