Question

pls help me with it. you just need to answer the question in Appointment.Java, There is...

pls help me with it.

you just need to answer the question in Appointment.Java, There is only 1 question u need to answer!

Appointment.Java

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, TimeSlot timeSlot) {

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 parameter Appointment.

* we say two appointments conflict if they are with the same doctor

* and the timeSlots overlap.

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

*/

public boolean conflictsWith(Appointment other) {

return false; //TO BE COMPLETED

}

}

This is the test file to test if the codes are working.

AppointmentTest.JAVA

package option1.stage3;

import common.Graded;

import option1.stage1.*;

import option1.stage2.TimeSlot;

import static org.junit.Assert.*;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Date;

import java.text.SimpleDateFormat;

import org.junit.AfterClass;

import org.junit.Test;

public class AppointmentTest {

private static int score = 0;

private static String result = "";

@Test @Graded(marks=5, description="Appointment:conflictsWith(Appointment)")

public void testConflictsWith() {

Doctor d1 = new Doctor("Rachel", "Pediatrician");

Doctor d2 = new Doctor("James", "Oncologist");

Doctor d3 = new Doctor("Rachel", "General Practitioner");

Doctor d5 = new Doctor("rachel", "pediatrician");

Time a = new Time(12, 0);

Time b = new Time(12, 15);

Time c = new Time(12, 30);

Time d = new Time(12, 45);

Time e = new Time(13, 0);

TimeSlot slot1 = new TimeSlot(a, b);

TimeSlot slot3 = new TimeSlot(c, d);

TimeSlot slot4 = new TimeSlot(b, d);

TimeSlot slot7 = new TimeSlot(a, e);

Patient randomPatient = new Patient("Dummy");

Appointment a1 = new Appointment(d1, randomPatient , slot1);

Appointment a2 = new Appointment(d1, randomPatient , slot3);

assertFalse(a1.conflictsWith(a2));

Appointment a3 = new Appointment(d2, randomPatient , slot1);

assertFalse(a1.conflictsWith(a3));

Appointment a4 = new Appointment(d1, randomPatient , slot7);

assertTrue(a2.conflictsWith(a4));

Appointment a5 = new Appointment(d5, randomPatient , slot4);

assertFalse(a1.conflictsWith(a5));

Appointment a6 = new Appointment(d3, randomPatient , slot1);

assertFalse(a1.conflictsWith(a6));

Appointment a7 = new Appointment(d5, randomPatient , slot7);

assertTrue(a1.conflictsWith(a7));

score+=5;

result+="Appointment:conflictsWith(Appointment) passed\n";

}

//log reporting

@AfterClass

public static void wrapUp() throws IOException {

System.out.println(result.substring(0,result.length()-1));

System.out.println("--------------------------------------------");

System.out.println("Total: "+score+" out of 5");

System.out.println("--------------------------------------------\n\n");

String timeStamp = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date());

File file = new File("log/Appointment"+timeStamp+".txt");

FileWriter writer = new FileWriter(file);

writer.write(result.substring(0,result.length()-1)+"\n");

writer.write("--------------------------------------------\n");

writer.write(score+"\n");

writer.flush();

writer.close();

}

}

The two files below are also you will need to make the Appointment.JAVA run!

TimeSlot.JAVA

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 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) {

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

endTime = startTime.advance(4);

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

endTime = startTime.advance(1);

} this.endTime = endTime;

}

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 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) {

if((this.getEndTime().compareTo(other.getStartTime()) == 1)&&

(this.getEndTime().compareTo(other.getEndTime()) == -1)){

return true;

}else if((this.getStartTime().compareTo(other.getStartTime()) == 1) && (this.getStartTime().compareTo(other.getEndTime()) == -1)){ return true; }else if(this.getStartTime().compareTo(other.getStartTime()) == 0){ return true; }else if(this.getEndTime().compareTo(other.getEndTime()) == 0){ return true; } return false;

Time.JAVA

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

}

}

Doctor.JAVA

package option1.stage1;

import java.util.ArrayList;

import java.util.Arrays;

public class Doctor {

private String name;

private String speciality;

/*

* note specialities is static means that only one instance is created

* irrespective of number of Doctor instances and that one instance of

* specialities is shared by all instances. it can be accessed by Doctor.specialities

*/

public static ArrayList<String> specialities = new ArrayList<String>(Arrays.asList("General Practitioner", "Dentist", "Surgeon",

"Pediatrician", "Podiatrician", "Dermatologist",

"Radiologist", "Pathologist", "Physician",

"Obstetrician", "Gynaecologist", "Oncologist"));

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getSpeciality() {

return speciality;

}

/**

* set speciality of the calling object to the passed value IF the value

* exists (case insensitive) in the ArrayList specialities.

* If the passed value doesn't exist in the ArrayList specialities, set

* the speciality of the calling object to "General Practitioner".

* For example, if spec = "oncologist" or if spec = "O

* ncologist" or spec = "ONCOLOGIST",

* instance variable speciality should become "Oncologist"

* @param spec

*/

public void setSpeciality(String spec) {

boolean nco=false;

for (String str:specialities)

{

if(str.equalsIgnoreCase(spec))

{

nco=true;

this.speciality=str;

break;

}

}

if(nco==false)

{

this.speciality ="General Practitioner";

}

}

//TO BE COMPLETLED}

public Doctor(String name, String spec) {

setName(name);

setSpeciality(spec);

}

public String toString() {

return "Dr. "+name+" ("+speciality+")";

}

/**

*

* @param other

* @return true if the names and specialities of the calling object and the parameter object

* are the same (case insensitive)

*/

public boolean equals(Object other) {

if(other instanceof Doctor)

return name.equalsIgnoreCase(((Doctor)other).name) && speciality.equalsIgnoreCase(((Doctor)other).speciality);

else

return false;

}

}

Patient.JAVA

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;

}

}

Let me know if any codes above are no working!

thank you so much!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for Appointment.java. There was only a couple of lines of code to be added. Let me know if you have any doubts. If you are satisfied with the solution, please rate the answer. Thanks

Other classes are not attached, as there was no change in any of them.

// Appointment.java

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, TimeSlot timeSlot) {

            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 parameter Appointment.

      *

      *         we say two appointments conflict if they are with the same doctor

      *

      *         and the timeSlots overlap.

      *

      *         HINT: Use method equals from Doctor class and method overlapsWith

      *         from TimeSlot class

      */

      public boolean conflictsWith(Appointment other) {

            if (this.doctor.equals(other.doctor)

                       && this.timeSlot.overlapsWith(other.timeSlot)) {

                  //same doctor and time slot overlaps

                  return true;

            }

            return false; // TO BE COMPLETED

      }

}

/*OUTPUT*/

Appointment:conflictsWith(Appointment) passed

--------------------------------------------

Total: 5 out of 5

--------------------------------------------

/*JUnit test result screenshot */

Runs: 1/1 Errors: 0 Failures: 0 函0ptionistage3AppointmentTest [Runner: JUnit testConflictsWith (0.064 s)

Add a comment
Know the answer?
Add Answer to:
pls help me with it. you just need to answer the question in Appointment.Java, There is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement a greedy strategy in JAVA which takes in a list of job object ( each...

    Implement a greedy strategy in JAVA which takes in a list of job object ( each job object consist of Job id (integer) , startTime (float) and endTime(float)) and outputs a list of non-conflicting jobs according to their start time. (Implement the given method provided in the code). Example of Input: id startTime endTime 1 4 7 2 3 5 3 7 9 CODE import java.util.Scanner; import java.util.List; import java.util.ArrayList; import java.io.InputStream; public class JobScheduling { public static final Strategy...

  • Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java...

    Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>();   // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString());       //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234");    // printing information System.out.println(part2.toString());    //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...

  • Practically dying here with this, need help ASAP, just need to do hide(), hideBoth(), and matchFound(),...

    Practically dying here with this, need help ASAP, just need to do hide(), hideBoth(), and matchFound(), then implement them, so far in my version i tentatively made them, but I don't know ho to implement them so i posted the original code before i made my version of the three methods listed above. Need help fast, this is ridiculous. Implement just one requirement at a time. For example, try implementing the case where after the user clicks 2 squares, both...

  • // I need help with the following questions. Please use java programming ECLIPSE language to solve...

    // I need help with the following questions. Please use java programming ECLIPSE language to solve the questions. YOU ONLY NEED TO DIRECTLY COPY IT IN YOUR ECLIPSE APPLICATION AND RUN IT. I NEED THOSE PART WHICH IS SAYS --> "TO BE COMPLETED" I NEED HELP WITH [GET*] AND [REPLACE ALL] AND [ADD INT DOUBLE] PLEASE. import java.util.ArrayList; public class CustomArrayList { //instance variables public int[] data; //data.length gives the capacity public int nItems; //nItems gives items currently in the...

  • Please help with Java programming! This code is to implement a Clock class. Use my beginning...

    Please help with Java programming! This code is to implement a Clock class. Use my beginning code below to test your implementation. public class Clock { // Declare your fields here /** * The constructor builds a Clock object and sets time to 00:00 * and the alarm to 00:00, also. * */ public Clock() { setHr(0); setMin(0); setAlarmHr(0); setAlarmMin(0); } /** * setHr() will validate and set the value of the hr field * for the clock. * *...

  • I need help with adding comments to my code and I need a uml diagram for...

    I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...

  • Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a...

    Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a queue. Then you are going to use the queue to store animals. 1. Write a LinkedQueue class that implements the QueueADT.java interface using links. 2. Textbook implementation uses a count variable to keep track of the elements in the queue. Don't use variable count in your implementation (points will be deducted if you use instance variable count). You may use a local integer variable...

  • Hi All, Can someone please help me correct the selection sort method in my program. the...

    Hi All, Can someone please help me correct the selection sort method in my program. the output for the first and last sorted integers are wrong compared with the bubble and merge sort. and for the radix i have no idea. See program below import java.io.*; import java.util.ArrayList; import java.util.Scanner; public class Sort { static ArrayList<Integer> Data1 = new ArrayList<Integer>(); static ArrayList<Integer> Data2 = new ArrayList<Integer>(); static ArrayList<Integer> Data3 = new ArrayList<Integer>(); static ArrayList<Integer> Data4 = new ArrayList<Integer>(); static int...

  • S. The following code has some errors Please point out and correct them. (There are more...

    S. The following code has some errors Please point out and correct them. (There are more than five errors #ineludo <iostream> uaing std reout uning stdsiendi class Time public Time (int-o, int0) void printTime) const void setMinute(int m) const private int hour int minute Time: :Time (int h, int m) hour (h o & hour< 24) h 0 setMinute (m) Time::setMinute (int m) minute = (m >-O && m < 60) ? m : 0; void printTime () cout <...

  • need help with this JAVA lab, the starting code for the lab is below. directions: The...

    need help with this JAVA lab, the starting code for the lab is below. directions: The Clock class has fields to store the hours, minutes and meridian (a.m. or p.m.) of the clock. This class also has a method that compares two Clock instances and returns the one that is set to earlier in the day. The blahblahblah class has a method to get the hours, minutes and meridian from the user. Then a main method in that class creates...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT