I need to create a LinkedQueue program that is a simulation of a Dentist. I need
ID: 3544376 • Letter: I
Question
I need to create a LinkedQueue program that is a simulation of a Dentist.
I need a patient class declare which has the description of customer and what work needs to be done to the patient.
Ex. Emma Lawyer(Description) 10:00 (Arrive Time) Cleaning (method)
Next, I need a Dentist Class. There is only ONE dentist so:
-The Dentist reads in a patient in order of time arrived.
-If Queue is not empty, than the patient is fetched and dental work is done in the following way:
If the patients service needs : Cleaning (30 min), Checkup (15 Minute), ToothExtract(30), Braces(45)
Each patient comes to the dentist with an arrival time and leave time is computed after getting their dental work done; however leave time = waiting time + service time (which is the numbers in the dental work); waiting time is computed using the previous patient
Explanation / Answer
import java.util.*;
public class DentalWork {
public static void main(String[] args) {
Dentist dentist = new Dentist();
Patient p;
p = new Patient();
p.description = "Emmy Lawyer";
p.arriveTime = 1000;
p.dentalWork = "Cleaning";
dentist.insertPatient(p);
p = new Patient(); p.description = "Jack Carpenter";
p.arriveTime = 1010;
p.dentalWork = "Checkup";
dentist.insertPatient(p);
p = new Patient();
p.description = "Janet Engineer";
p.arriveTime = 1040;
p.dentalWork = "Braces";
dentist.insertPatient(p);
dentist.createLog();
}
}
class Patient {
String description;
int arriveTime;
int leaveTime;
String dentalWork;
int waitTime;
Patient next;
};
class Dentist {
Patient firstPatient;
Dentist() {
firstPatient = null;
}
public void insertPatient(Patient p) {
if (firstPatient == null) {
firstPatient = p;
firstPatient.next = null;
return;
}
Patient temp = firstPatient;
Patient prev = null;
while (temp != null && p.arriveTime > temp.arriveTime) {
//System.out.println("name: "+temp.description);
prev = temp;
temp = temp.next;
}
if (temp == null) {
prev.next = p;
p.next = null;
}
}
public void popPatient() {
if (firstPatient != null) {
Patient temp = firstPatient;
firstPatient = temp.next;
temp = null;
}
}
public int addTime(int time, int minutes) {
int hh = time/100;
int min = time%100;
if ((min + minutes)/ 60 > 0) { hh+= (min+minutes)/60; min = (min+minutes)%60; }
else { min = min + minutes;}
int finTime= (hh*100 + min);
return finTime;
}
public int getTimeDiff(int time1, int time2) {
int hh1 = time1/100 ; int mm1 = time1%100;
int hh2 = time2/100 ; int mm2 = time2%100;
if (hh1 > hh2 || (hh1 == hh2 && mm1 > mm2)) {
return ((hh1-hh2)*60 + (mm1-mm2));
}
else return 0;
}
public void createLog() {
int lastLeaveTime = firstPatient.arriveTime;
int numPatient = 1;
System.out.println("Name Description Arrival Time Dental Work Wait Time Leave Time");
while(firstPatient != null) {
int serviceTime = 0;
if (firstPatient.dentalWork.equals("Cleaning")) {
serviceTime = 30;
} else if (firstPatient.dentalWork.equals("Checkup")) {
serviceTime = 15;
} else if (firstPatient.dentalWork.equals("ToothExtract")) {
serviceTime = 30;
} else if (firstPatient.dentalWork.equals("Braces")) {
serviceTime = 45;
}
firstPatient.waitTime = getTimeDiff(lastLeaveTime,firstPatient.arriveTime);
// System.out.println("lastLeavetime: " + lastLeaveTime +" fp.arrivetime: " + firstPatient.arriveTime + " wt: " + firstPatient.waitTime);
firstPatient.leaveTime = addTime(firstPatient.arriveTime, firstPatient.waitTime + serviceTime);
// System.out.println("fp.at:" + firstPatient.arriveTime + " addtime: " + (firstPatient.waitTime + serviceTime) + " lt: " + firstPatient.leaveTime);
lastLeaveTime = firstPatient.leaveTime;
System.out.println("Patient "+numPatient+" - "+ firstPatient.description + " " + firstPatient.arriveTime + " " + firstPatient.dentalWork + " "+ firstPatient.waitTime + " Minutes " + firstPatient.leaveTime);
numPatient++;
popPatient();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.