SlideShare a Scribd company logo
Here is how the code works
1. Patient.java is an Abstract Class which contains the required attributes and a constructor for
initializing the Patient object
2. PatientImpl.java is a class which extends the Abstract class Patient.java and contains a
constructor which makes a call to the superclass and initializes the superclass with passed
arguments
3. PatientComparator.java is a class which implements the comparator interface and specfies the
criteria for comparing two Patient objects
4. Main.java drives the complete program by providing a menu to the user with the three options
that is for adding a patient, finding the next highest priority patient to be served and exiting the
program
Please find the code as follows:-
Patient.java Code:-
package com.chegg.patient;
import java.util.Date;
abstract class Patient {
private String name;
private Date dob;
private Date admission;
private String complaint;
private int priority;
public Patient(String name, Date dob, Date admission, String complaint, int priority) {
this.name = name;
this.dob = dob;
this.admission = admission;
this.complaint = complaint;
this.priority = priority;
}
public String toString() {
return this.name + this.dob + this.admission + this.complaint + this.priority;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getDob() {
return dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
public Date getAdmission() {
return admission;
}
public void setAdmission(Date admission) {
this.admission = admission;
}
public String getComplaint() {
return complaint;
}
public void setComplaint(String complaint) {
this.complaint = complaint;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
}
PatientImpl.java Code
package com.chegg.patient;
import java.util.Date;
public class PatientImpl extends Patient {
public PatientImpl(String name, Date dob, Date admission, String complaint, int priority) {
super(name, dob, admission, complaint, priority);
}
}
PatientComparator.java Code
package com.chegg.patient;
import java.util.Comparator;
public class PatientComparator implements Comparator {
@Override
public int compare(Patient arg0, Patient arg1) {
if(arg0.getPriority() == arg1.getPriority()){
if(arg0.getAdmission().compareTo(arg1.getAdmission())==-1){
return -1;
}
else
return 1;
}
if(arg0.getPriority() comparator = new PatientComparator();
PriorityQueue Pq = new PriorityQueue(10, comparator);
while (true) {
System.out.println("1. Enter New Patient Data");
System.out.println("2. Retrieve Next Patient to treat");
System.out.println("3. Exit");
choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1: {
System.out.println("Enter Name");
name = sc.nextLine();
System.out.println("Enter Date of birth in format yyyy-mm-dd");
String dob_String = sc.next();
dob = parseDate(dob_String);
admission = new Date();
System.out.println("Enter Complaint");
sc.nextLine();
complaint = sc.nextLine();
System.out.println("Enter Priority");
priority = sc.nextInt();
Patient myPatient = new PatientImpl(name, dob, admission, complaint, priority);
Pq.add(myPatient);
System.out.println(myPatient.toString());
break;
}
case 2: {
if (Pq.size() > 0) {
Patient nextPatient = Pq.remove();
System.out.println(nextPatient.toString());
}else
System.out.println("No Patients Pending");
break;
}
case 3: {
if(Pq.size()>0){
System.out.println("Patients are pending in the queue");
continue;
}else{
sc.close();
System.exit(0);
}
}
}
}
}
public static Date parseDate(String date) {
try {
return new SimpleDateFormat("yyyy-MM-dd").parse(date);
} catch (ParseException e) {
return null;
}
}
}
Solution
Here is how the code works
1. Patient.java is an Abstract Class which contains the required attributes and a constructor for
initializing the Patient object
2. PatientImpl.java is a class which extends the Abstract class Patient.java and contains a
constructor which makes a call to the superclass and initializes the superclass with passed
arguments
3. PatientComparator.java is a class which implements the comparator interface and specfies the
criteria for comparing two Patient objects
4. Main.java drives the complete program by providing a menu to the user with the three options
that is for adding a patient, finding the next highest priority patient to be served and exiting the
program
Please find the code as follows:-
Patient.java Code:-
package com.chegg.patient;
import java.util.Date;
abstract class Patient {
private String name;
private Date dob;
private Date admission;
private String complaint;
private int priority;
public Patient(String name, Date dob, Date admission, String complaint, int priority) {
this.name = name;
this.dob = dob;
this.admission = admission;
this.complaint = complaint;
this.priority = priority;
}
public String toString() {
return this.name + this.dob + this.admission + this.complaint + this.priority;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getDob() {
return dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
public Date getAdmission() {
return admission;
}
public void setAdmission(Date admission) {
this.admission = admission;
}
public String getComplaint() {
return complaint;
}
public void setComplaint(String complaint) {
this.complaint = complaint;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
}
PatientImpl.java Code
package com.chegg.patient;
import java.util.Date;
public class PatientImpl extends Patient {
public PatientImpl(String name, Date dob, Date admission, String complaint, int priority) {
super(name, dob, admission, complaint, priority);
}
}
PatientComparator.java Code
package com.chegg.patient;
import java.util.Comparator;
public class PatientComparator implements Comparator {
@Override
public int compare(Patient arg0, Patient arg1) {
if(arg0.getPriority() == arg1.getPriority()){
if(arg0.getAdmission().compareTo(arg1.getAdmission())==-1){
return -1;
}
else
return 1;
}
if(arg0.getPriority() comparator = new PatientComparator();
PriorityQueue Pq = new PriorityQueue(10, comparator);
while (true) {
System.out.println("1. Enter New Patient Data");
System.out.println("2. Retrieve Next Patient to treat");
System.out.println("3. Exit");
choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1: {
System.out.println("Enter Name");
name = sc.nextLine();
System.out.println("Enter Date of birth in format yyyy-mm-dd");
String dob_String = sc.next();
dob = parseDate(dob_String);
admission = new Date();
System.out.println("Enter Complaint");
sc.nextLine();
complaint = sc.nextLine();
System.out.println("Enter Priority");
priority = sc.nextInt();
Patient myPatient = new PatientImpl(name, dob, admission, complaint, priority);
Pq.add(myPatient);
System.out.println(myPatient.toString());
break;
}
case 2: {
if (Pq.size() > 0) {
Patient nextPatient = Pq.remove();
System.out.println(nextPatient.toString());
}else
System.out.println("No Patients Pending");
break;
}
case 3: {
if(Pq.size()>0){
System.out.println("Patients are pending in the queue");
continue;
}else{
sc.close();
System.exit(0);
}
}
}
}
}
public static Date parseDate(String date) {
try {
return new SimpleDateFormat("yyyy-MM-dd").parse(date);
} catch (ParseException e) {
return null;
}
}
}

More Related Content

Similar to Here is how the code works1. Patient.java is an Abstract Class whi.pdf

Hello. Im creating a class called Bill. I need to design the class.pdf
Hello. Im creating a class called Bill. I need to design the class.pdfHello. Im creating a class called Bill. I need to design the class.pdf
Hello. Im creating a class called Bill. I need to design the class.pdf
barristeressaseren71
 
import java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdfimport java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdf
anupamagarud8
 
Jdk1.5 Features
Jdk1.5 FeaturesJdk1.5 Features
Jdk1.5 Features
india_mani
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
MuhammadTalha436
 
Icom4015 lecture15-f16
Icom4015 lecture15-f16Icom4015 lecture15-f16
Icom4015 lecture15-f16
BienvenidoVelezUPR
 
Pragmatic unittestingwithj unit
Pragmatic unittestingwithj unitPragmatic unittestingwithj unit
Pragmatic unittestingwithj unit
liminescence
 
package s3; Copy paste this Java Template and save it as Emer.pdf
package s3;  Copy paste this Java Template and save it as Emer.pdfpackage s3;  Copy paste this Java Template and save it as Emer.pdf
package s3; Copy paste this Java Template and save it as Emer.pdf
arakalamkah11
 
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
ShashikantSathe3
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
Pokpitch Patcharadamrongkul
 
How to fix these erros The method sortListltTgt in the.pdf
How to fix these erros The method sortListltTgt in the.pdfHow to fix these erros The method sortListltTgt in the.pdf
How to fix these erros The method sortListltTgt in the.pdf
shahidipen68
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Subhash Chandran
 
write a java program to accept the names of three items and their pric.docx
write a java program to accept the names of three items and their pric.docxwrite a java program to accept the names of three items and their pric.docx
write a java program to accept the names of three items and their pric.docx
lez31palka
 
Objective Min-heap queue with customized comparatorHospital emerg.pdf
Objective Min-heap queue with customized comparatorHospital emerg.pdfObjective Min-heap queue with customized comparatorHospital emerg.pdf
Objective Min-heap queue with customized comparatorHospital emerg.pdf
ezhilvizhiyan
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 
Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Anton Arhipov
 
Class 10
Class 10Class 10
Java session4
Java session4Java session4
Java session4
Jigarthacker
 
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdfBasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
ankitmobileshop235
 
Java methods or Subroutines or Functions
Java methods or Subroutines or FunctionsJava methods or Subroutines or Functions
Java methods or Subroutines or Functions
Kuppusamy P
 

Similar to Here is how the code works1. Patient.java is an Abstract Class whi.pdf (20)

FunctionalInterfaces
FunctionalInterfacesFunctionalInterfaces
FunctionalInterfaces
 
Hello. Im creating a class called Bill. I need to design the class.pdf
Hello. Im creating a class called Bill. I need to design the class.pdfHello. Im creating a class called Bill. I need to design the class.pdf
Hello. Im creating a class called Bill. I need to design the class.pdf
 
import java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdfimport java.util.ArrayList; import java.util.List; import java.u.pdf
import java.util.ArrayList; import java.util.List; import java.u.pdf
 
Jdk1.5 Features
Jdk1.5 FeaturesJdk1.5 Features
Jdk1.5 Features
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
Icom4015 lecture15-f16
Icom4015 lecture15-f16Icom4015 lecture15-f16
Icom4015 lecture15-f16
 
Pragmatic unittestingwithj unit
Pragmatic unittestingwithj unitPragmatic unittestingwithj unit
Pragmatic unittestingwithj unit
 
package s3; Copy paste this Java Template and save it as Emer.pdf
package s3;  Copy paste this Java Template and save it as Emer.pdfpackage s3;  Copy paste this Java Template and save it as Emer.pdf
package s3; Copy paste this Java Template and save it as Emer.pdf
 
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
How to fix these erros The method sortListltTgt in the.pdf
How to fix these erros The method sortListltTgt in the.pdfHow to fix these erros The method sortListltTgt in the.pdf
How to fix these erros The method sortListltTgt in the.pdf
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
write a java program to accept the names of three items and their pric.docx
write a java program to accept the names of three items and their pric.docxwrite a java program to accept the names of three items and their pric.docx
write a java program to accept the names of three items and their pric.docx
 
Objective Min-heap queue with customized comparatorHospital emerg.pdf
Objective Min-heap queue with customized comparatorHospital emerg.pdfObjective Min-heap queue with customized comparatorHospital emerg.pdf
Objective Min-heap queue with customized comparatorHospital emerg.pdf
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
 
Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012
 
Class 10
Class 10Class 10
Class 10
 
Java session4
Java session4Java session4
Java session4
 
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdfBasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
 
Java methods or Subroutines or Functions
Java methods or Subroutines or FunctionsJava methods or Subroutines or Functions
Java methods or Subroutines or Functions
 

More from arasanlethers

#include SDLSDL.hSDL_Surface Background = NULL; SDL_Surface.pdf
#include SDLSDL.hSDL_Surface Background = NULL; SDL_Surface.pdf#include SDLSDL.hSDL_Surface Background = NULL; SDL_Surface.pdf
#include SDLSDL.hSDL_Surface Background = NULL; SDL_Surface.pdf
arasanlethers
 
C, D, and E are wrong and involve random constants. Thisnarrows it d.pdf
C, D, and E are wrong and involve random constants. Thisnarrows it d.pdfC, D, and E are wrong and involve random constants. Thisnarrows it d.pdf
C, D, and E are wrong and involve random constants. Thisnarrows it d.pdf
arasanlethers
 
AnswerOogenesis is the process by which ovum mother cells or oogo.pdf
AnswerOogenesis is the process by which ovum mother cells or oogo.pdfAnswerOogenesis is the process by which ovum mother cells or oogo.pdf
AnswerOogenesis is the process by which ovum mother cells or oogo.pdf
arasanlethers
 
AnswerB) S. typhimuium gains access to the host by crossing the.pdf
AnswerB) S. typhimuium gains access to the host by crossing the.pdfAnswerB) S. typhimuium gains access to the host by crossing the.pdf
AnswerB) S. typhimuium gains access to the host by crossing the.pdf
arasanlethers
 
Answer question1,2,4,5Ion–dipole interactionsAffinity of oxygen .pdf
Answer question1,2,4,5Ion–dipole interactionsAffinity of oxygen .pdfAnswer question1,2,4,5Ion–dipole interactionsAffinity of oxygen .pdf
Answer question1,2,4,5Ion–dipole interactionsAffinity of oxygen .pdf
arasanlethers
 
A Letter to myself!Hi to myself!Now that I am an Engineer with a.pdf
A Letter to myself!Hi to myself!Now that I am an Engineer with a.pdfA Letter to myself!Hi to myself!Now that I am an Engineer with a.pdf
A Letter to myself!Hi to myself!Now that I am an Engineer with a.pdf
arasanlethers
 
Particulars Amount ($) Millons a) Purchase consideratio.pdf
     Particulars  Amount ($) Millons          a) Purchase consideratio.pdf     Particulars  Amount ($) Millons          a) Purchase consideratio.pdf
Particulars Amount ($) Millons a) Purchase consideratio.pdf
arasanlethers
 
2 = 14.191,     df = 9,2df = 1.58 ,         P(2 14.191) = .pdf
2 = 14.191,     df = 9,2df = 1.58 ,         P(2  14.191) = .pdf2 = 14.191,     df = 9,2df = 1.58 ,         P(2  14.191) = .pdf
2 = 14.191,     df = 9,2df = 1.58 ,         P(2 14.191) = .pdf
arasanlethers
 
while determining the pH the pH of the water is n.pdf
                     while determining the pH the pH of the water is n.pdf                     while determining the pH the pH of the water is n.pdf
while determining the pH the pH of the water is n.pdf
arasanlethers
 
Quantum Numbers and Atomic Orbitals By solving t.pdf
                     Quantum Numbers and Atomic Orbitals  By solving t.pdf                     Quantum Numbers and Atomic Orbitals  By solving t.pdf
Quantum Numbers and Atomic Orbitals By solving t.pdf
arasanlethers
 
They are molecules that are mirror images of each.pdf
                     They are molecules that are mirror images of each.pdf                     They are molecules that are mirror images of each.pdf
They are molecules that are mirror images of each.pdf
arasanlethers
 
Well u put so many type of compounds here.Generally speakingi) t.pdf
Well u put so many type of compounds here.Generally speakingi) t.pdfWell u put so many type of compounds here.Generally speakingi) t.pdf
Well u put so many type of compounds here.Generally speakingi) t.pdf
arasanlethers
 
Ventilation is the process of air going in and out of lungs. Increas.pdf
Ventilation is the process of air going in and out of lungs. Increas.pdfVentilation is the process of air going in and out of lungs. Increas.pdf
Ventilation is the process of air going in and out of lungs. Increas.pdf
arasanlethers
 
A1) A living being or an individual is known as an organism and it i.pdf
A1) A living being or an individual is known as an organism and it i.pdfA1) A living being or an individual is known as an organism and it i.pdf
A1) A living being or an individual is known as an organism and it i.pdf
arasanlethers
 
there are laws and regulations that would pertain to an online breac.pdf
there are laws and regulations that would pertain to an online breac.pdfthere are laws and regulations that would pertain to an online breac.pdf
there are laws and regulations that would pertain to an online breac.pdf
arasanlethers
 
The false statement among the given list is “Territoriality means ho.pdf
The false statement among the given list is “Territoriality means ho.pdfThe false statement among the given list is “Territoriality means ho.pdf
The false statement among the given list is “Territoriality means ho.pdf
arasanlethers
 
The current article is discussing about the role of SOX4 geneprotei.pdf
The current article is discussing about the role of SOX4 geneprotei.pdfThe current article is discussing about the role of SOX4 geneprotei.pdf
The current article is discussing about the role of SOX4 geneprotei.pdf
arasanlethers
 
The major similarities between rocks and minerals are as follows1.pdf
The major similarities between rocks and minerals are as follows1.pdfThe major similarities between rocks and minerals are as follows1.pdf
The major similarities between rocks and minerals are as follows1.pdf
arasanlethers
 
Pipelining understandingPipelining is running multiple stages of .pdf
Pipelining understandingPipelining is running multiple stages of .pdfPipelining understandingPipelining is running multiple stages of .pdf
Pipelining understandingPipelining is running multiple stages of .pdf
arasanlethers
 
main.cpp #include iostream #include iomanip #include S.pdf
main.cpp #include iostream #include iomanip #include S.pdfmain.cpp #include iostream #include iomanip #include S.pdf
main.cpp #include iostream #include iomanip #include S.pdf
arasanlethers
 

More from arasanlethers (20)

#include SDLSDL.hSDL_Surface Background = NULL; SDL_Surface.pdf
#include SDLSDL.hSDL_Surface Background = NULL; SDL_Surface.pdf#include SDLSDL.hSDL_Surface Background = NULL; SDL_Surface.pdf
#include SDLSDL.hSDL_Surface Background = NULL; SDL_Surface.pdf
 
C, D, and E are wrong and involve random constants. Thisnarrows it d.pdf
C, D, and E are wrong and involve random constants. Thisnarrows it d.pdfC, D, and E are wrong and involve random constants. Thisnarrows it d.pdf
C, D, and E are wrong and involve random constants. Thisnarrows it d.pdf
 
AnswerOogenesis is the process by which ovum mother cells or oogo.pdf
AnswerOogenesis is the process by which ovum mother cells or oogo.pdfAnswerOogenesis is the process by which ovum mother cells or oogo.pdf
AnswerOogenesis is the process by which ovum mother cells or oogo.pdf
 
AnswerB) S. typhimuium gains access to the host by crossing the.pdf
AnswerB) S. typhimuium gains access to the host by crossing the.pdfAnswerB) S. typhimuium gains access to the host by crossing the.pdf
AnswerB) S. typhimuium gains access to the host by crossing the.pdf
 
Answer question1,2,4,5Ion–dipole interactionsAffinity of oxygen .pdf
Answer question1,2,4,5Ion–dipole interactionsAffinity of oxygen .pdfAnswer question1,2,4,5Ion–dipole interactionsAffinity of oxygen .pdf
Answer question1,2,4,5Ion–dipole interactionsAffinity of oxygen .pdf
 
A Letter to myself!Hi to myself!Now that I am an Engineer with a.pdf
A Letter to myself!Hi to myself!Now that I am an Engineer with a.pdfA Letter to myself!Hi to myself!Now that I am an Engineer with a.pdf
A Letter to myself!Hi to myself!Now that I am an Engineer with a.pdf
 
Particulars Amount ($) Millons a) Purchase consideratio.pdf
     Particulars  Amount ($) Millons          a) Purchase consideratio.pdf     Particulars  Amount ($) Millons          a) Purchase consideratio.pdf
Particulars Amount ($) Millons a) Purchase consideratio.pdf
 
2 = 14.191,     df = 9,2df = 1.58 ,         P(2 14.191) = .pdf
2 = 14.191,     df = 9,2df = 1.58 ,         P(2  14.191) = .pdf2 = 14.191,     df = 9,2df = 1.58 ,         P(2  14.191) = .pdf
2 = 14.191,     df = 9,2df = 1.58 ,         P(2 14.191) = .pdf
 
while determining the pH the pH of the water is n.pdf
                     while determining the pH the pH of the water is n.pdf                     while determining the pH the pH of the water is n.pdf
while determining the pH the pH of the water is n.pdf
 
Quantum Numbers and Atomic Orbitals By solving t.pdf
                     Quantum Numbers and Atomic Orbitals  By solving t.pdf                     Quantum Numbers and Atomic Orbitals  By solving t.pdf
Quantum Numbers and Atomic Orbitals By solving t.pdf
 
They are molecules that are mirror images of each.pdf
                     They are molecules that are mirror images of each.pdf                     They are molecules that are mirror images of each.pdf
They are molecules that are mirror images of each.pdf
 
Well u put so many type of compounds here.Generally speakingi) t.pdf
Well u put so many type of compounds here.Generally speakingi) t.pdfWell u put so many type of compounds here.Generally speakingi) t.pdf
Well u put so many type of compounds here.Generally speakingi) t.pdf
 
Ventilation is the process of air going in and out of lungs. Increas.pdf
Ventilation is the process of air going in and out of lungs. Increas.pdfVentilation is the process of air going in and out of lungs. Increas.pdf
Ventilation is the process of air going in and out of lungs. Increas.pdf
 
A1) A living being or an individual is known as an organism and it i.pdf
A1) A living being or an individual is known as an organism and it i.pdfA1) A living being or an individual is known as an organism and it i.pdf
A1) A living being or an individual is known as an organism and it i.pdf
 
there are laws and regulations that would pertain to an online breac.pdf
there are laws and regulations that would pertain to an online breac.pdfthere are laws and regulations that would pertain to an online breac.pdf
there are laws and regulations that would pertain to an online breac.pdf
 
The false statement among the given list is “Territoriality means ho.pdf
The false statement among the given list is “Territoriality means ho.pdfThe false statement among the given list is “Territoriality means ho.pdf
The false statement among the given list is “Territoriality means ho.pdf
 
The current article is discussing about the role of SOX4 geneprotei.pdf
The current article is discussing about the role of SOX4 geneprotei.pdfThe current article is discussing about the role of SOX4 geneprotei.pdf
The current article is discussing about the role of SOX4 geneprotei.pdf
 
The major similarities between rocks and minerals are as follows1.pdf
The major similarities between rocks and minerals are as follows1.pdfThe major similarities between rocks and minerals are as follows1.pdf
The major similarities between rocks and minerals are as follows1.pdf
 
Pipelining understandingPipelining is running multiple stages of .pdf
Pipelining understandingPipelining is running multiple stages of .pdfPipelining understandingPipelining is running multiple stages of .pdf
Pipelining understandingPipelining is running multiple stages of .pdf
 
main.cpp #include iostream #include iomanip #include S.pdf
main.cpp #include iostream #include iomanip #include S.pdfmain.cpp #include iostream #include iomanip #include S.pdf
main.cpp #include iostream #include iomanip #include S.pdf
 

Recently uploaded

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 

Here is how the code works1. Patient.java is an Abstract Class whi.pdf

  • 1. Here is how the code works 1. Patient.java is an Abstract Class which contains the required attributes and a constructor for initializing the Patient object 2. PatientImpl.java is a class which extends the Abstract class Patient.java and contains a constructor which makes a call to the superclass and initializes the superclass with passed arguments 3. PatientComparator.java is a class which implements the comparator interface and specfies the criteria for comparing two Patient objects 4. Main.java drives the complete program by providing a menu to the user with the three options that is for adding a patient, finding the next highest priority patient to be served and exiting the program Please find the code as follows:- Patient.java Code:- package com.chegg.patient; import java.util.Date; abstract class Patient { private String name; private Date dob; private Date admission; private String complaint; private int priority; public Patient(String name, Date dob, Date admission, String complaint, int priority) { this.name = name; this.dob = dob; this.admission = admission; this.complaint = complaint; this.priority = priority; } public String toString() { return this.name + this.dob + this.admission + this.complaint + this.priority; } public String getName() { return name; } public void setName(String name) {
  • 2. this.name = name; } public Date getDob() { return dob; } public void setDob(Date dob) { this.dob = dob; } public Date getAdmission() { return admission; } public void setAdmission(Date admission) { this.admission = admission; } public String getComplaint() { return complaint; } public void setComplaint(String complaint) { this.complaint = complaint; } public int getPriority() { return priority; } public void setPriority(int priority) { this.priority = priority; } } PatientImpl.java Code package com.chegg.patient; import java.util.Date; public class PatientImpl extends Patient { public PatientImpl(String name, Date dob, Date admission, String complaint, int priority) { super(name, dob, admission, complaint, priority); } } PatientComparator.java Code
  • 3. package com.chegg.patient; import java.util.Comparator; public class PatientComparator implements Comparator { @Override public int compare(Patient arg0, Patient arg1) { if(arg0.getPriority() == arg1.getPriority()){ if(arg0.getAdmission().compareTo(arg1.getAdmission())==-1){ return -1; } else return 1; } if(arg0.getPriority() comparator = new PatientComparator(); PriorityQueue Pq = new PriorityQueue(10, comparator); while (true) { System.out.println("1. Enter New Patient Data"); System.out.println("2. Retrieve Next Patient to treat"); System.out.println("3. Exit"); choice = sc.nextInt(); sc.nextLine(); switch (choice) { case 1: { System.out.println("Enter Name"); name = sc.nextLine(); System.out.println("Enter Date of birth in format yyyy-mm-dd"); String dob_String = sc.next(); dob = parseDate(dob_String); admission = new Date(); System.out.println("Enter Complaint"); sc.nextLine(); complaint = sc.nextLine(); System.out.println("Enter Priority"); priority = sc.nextInt(); Patient myPatient = new PatientImpl(name, dob, admission, complaint, priority); Pq.add(myPatient); System.out.println(myPatient.toString());
  • 4. break; } case 2: { if (Pq.size() > 0) { Patient nextPatient = Pq.remove(); System.out.println(nextPatient.toString()); }else System.out.println("No Patients Pending"); break; } case 3: { if(Pq.size()>0){ System.out.println("Patients are pending in the queue"); continue; }else{ sc.close(); System.exit(0); } } } } } public static Date parseDate(String date) { try { return new SimpleDateFormat("yyyy-MM-dd").parse(date); } catch (ParseException e) { return null; } } } Solution Here is how the code works 1. Patient.java is an Abstract Class which contains the required attributes and a constructor for initializing the Patient object
  • 5. 2. PatientImpl.java is a class which extends the Abstract class Patient.java and contains a constructor which makes a call to the superclass and initializes the superclass with passed arguments 3. PatientComparator.java is a class which implements the comparator interface and specfies the criteria for comparing two Patient objects 4. Main.java drives the complete program by providing a menu to the user with the three options that is for adding a patient, finding the next highest priority patient to be served and exiting the program Please find the code as follows:- Patient.java Code:- package com.chegg.patient; import java.util.Date; abstract class Patient { private String name; private Date dob; private Date admission; private String complaint; private int priority; public Patient(String name, Date dob, Date admission, String complaint, int priority) { this.name = name; this.dob = dob; this.admission = admission; this.complaint = complaint; this.priority = priority; } public String toString() { return this.name + this.dob + this.admission + this.complaint + this.priority; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Date getDob() { return dob;
  • 6. } public void setDob(Date dob) { this.dob = dob; } public Date getAdmission() { return admission; } public void setAdmission(Date admission) { this.admission = admission; } public String getComplaint() { return complaint; } public void setComplaint(String complaint) { this.complaint = complaint; } public int getPriority() { return priority; } public void setPriority(int priority) { this.priority = priority; } } PatientImpl.java Code package com.chegg.patient; import java.util.Date; public class PatientImpl extends Patient { public PatientImpl(String name, Date dob, Date admission, String complaint, int priority) { super(name, dob, admission, complaint, priority); } } PatientComparator.java Code package com.chegg.patient; import java.util.Comparator; public class PatientComparator implements Comparator { @Override
  • 7. public int compare(Patient arg0, Patient arg1) { if(arg0.getPriority() == arg1.getPriority()){ if(arg0.getAdmission().compareTo(arg1.getAdmission())==-1){ return -1; } else return 1; } if(arg0.getPriority() comparator = new PatientComparator(); PriorityQueue Pq = new PriorityQueue(10, comparator); while (true) { System.out.println("1. Enter New Patient Data"); System.out.println("2. Retrieve Next Patient to treat"); System.out.println("3. Exit"); choice = sc.nextInt(); sc.nextLine(); switch (choice) { case 1: { System.out.println("Enter Name"); name = sc.nextLine(); System.out.println("Enter Date of birth in format yyyy-mm-dd"); String dob_String = sc.next(); dob = parseDate(dob_String); admission = new Date(); System.out.println("Enter Complaint"); sc.nextLine(); complaint = sc.nextLine(); System.out.println("Enter Priority"); priority = sc.nextInt(); Patient myPatient = new PatientImpl(name, dob, admission, complaint, priority); Pq.add(myPatient); System.out.println(myPatient.toString()); break; } case 2: { if (Pq.size() > 0) {
  • 8. Patient nextPatient = Pq.remove(); System.out.println(nextPatient.toString()); }else System.out.println("No Patients Pending"); break; } case 3: { if(Pq.size()>0){ System.out.println("Patients are pending in the queue"); continue; }else{ sc.close(); System.exit(0); } } } } } public static Date parseDate(String date) { try { return new SimpleDateFormat("yyyy-MM-dd").parse(date); } catch (ParseException e) { return null; } } }