Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming, Last Class to add: HospitalSystem. (Edit the code, please let me know if more is needed) //Person.java /** * The model of a

Java Programming, Last Class to add: HospitalSystem.

(Edit the code, please let me know if more is needed)image text in transcribedimage text in transcribed

//Person.java /** * The model of a person who has a name and a health number * that cannot be changed. */ public abstract class Person { /** * The name of the person. */ private String pname; /** * The health number of the person. */ private int healthNum; /** * Initialize an instance with the given name and health number. * * @param pName the person's name * @param pNumber the person's health number */ public Person(String pname, int pNumber) { this.pname = pname; this.pNumber = pNumber; } /** * Return the name of the person. * * @return the name of the person */ public String getName() { return pname; } /** * Return the health number of the person. * * @return the health number of the person */ public int getHealthNumber() { return healthNum; } /** * Change the name of the person. * * @param newName the name of the person */ public void setName(String newName) { pname = newName; } /** * Return a string representation of the person. * * @return a string representation of the person */ @Override public String toString() { return "Name: "+pname+" Health#: "+pNumber; } } /** * A method to test the Person class. */

//Patient.java import java.util.LinkedList; public class Patient extends Person{ String bedReference; LinkedList doctors; public Patient(String pName, int pNumber) { super(pName, pNumber); this.doctors = new LinkedList(); } public String getBedReference() { return bedReference; } public void setBedReference(String bedReference) { this.bedReference = bedReference; } public LinkedList getDoctors() { return doctors; } public void setDoctors(LinkedList doctors) { this.doctors = doctors; } @Override public String toString() { String text=""; if(bedReference!=null) { text+="Patient: "+this.getName()+" Health number: "+this.getHealthNumber()+" Bed reference: "+this.getBedReference(); if(!doctors.isEmpty()) { text+=" Doctors: "; for (Person person : doctors) { text+="\t"+person.getName()+" "; } } } else { text+="Patient: "+this.getName()+" Health number: "+this.getHealthNumber(); if(!doctors.isEmpty()) { text+=" Doctors: "; for (Person person : doctors) { text+="\t"+person.getName()+" "; } } } return text; } public static void main(String[] args) { Patient patient =new Patient("Aabid", 123456); Doctor doctor=new Doctor("Hilal","Oncology"); Doctor doctor1=new Doctor("Nasir","Podiatrist"); Doctor doctor2=new Doctor("Aadil","Psychiatrist"); Doctor doctor3=new Doctor("Saima","Oncology"); LinkedList docList=new LinkedList(); docList.add(doctor); docList.add(doctor1); docList.add(doctor2); docList.add(doctor3); patient.setDoctors(docList); patient.setBedReference("34"); System.out.println(patient); } }

// Doctor.java import java.util.LinkedList; import java.util.List; public class Doctor extends Person implements BasicDoctor{ String department; public List patients; public Doctor(String name, String department) { super(name); patients=new LinkedList(); this.department=department; } public List getPatients() { return patients; } public void addPatient(Person patient) { this.patients.add(patient); } // @Override //public String getName() { //return /ame; //} @Override public Person checkUp() throws Exception { if(this.patients.isEmpty()) throw new Exception("No patients to be checked up"); return this.patients.remove(0); } @Override public String toString() { return "Doctor: "+name+" Designation: "+department; } }

// Surgeon.java import java.util.List; public class Surgeon extends Doctor{ public Surgeon(String name, String department) { super(name, department); } @Override public String toString() { return "Surgeon: "+name+" Designation: "+department; } }

// interface BasicDoctor.java

// all are in package card

public interface BasicDoctor {

public Person checkUp() throws Exception;

}

// Ward.java

package dragon;

import java.util.ArrayList;

import java.util.LinkedList;

import java.util.List;

/**

* A ward of a hospital with a specified number of beds with consecutive labels.

*/

public class Ward {

private String name;

private int minBedLabel;

private int maxBedLabel;

private int length;

private LinkedList beds;

public Ward(String wName, int wMinBedLabel, int wMaxBedLabel)

{

length=wMaxBedLabel-wMinBedLabel;

// System.out.println(length);

if (wName == null || wName.equals(""))

throw new RuntimeException("The name of a ward cannot be null or empty. "+ "It is " + wName);

if (wMinBedLabel

throw new RuntimeException("The bed labels " + wMinBedLabel + " and " + wMaxBedLabel+ " are invalid as they cannot be negative and must have at least one bed.");

name = wName;

minBedLabel = wMinBedLabel;

beds = new LinkedList();

for(int i=0;i

beds.add(i, null);

}

}

/**

* Return the name of this ward.

*

* @return the name of this ward

*/

public String getName() {

return name;

}

public int getMinBedLabel() {

return minBedLabel;

}

public int getMaxBedLabel() {

return maxBedLabel;

}

/**

* Is bedLabel a valid external label for a bed?

*

* @param bedLabel a candidate bed label

* @return whether or not the provided label is within the range of possible labels

*/

public boolean isValidLabel(int bedLabel) {

return bedLabel >= minBedLabel && bedLabel

}

/**

* Return the internal/array index of the bed corresponding to the external label.

*

* @param bedLabel a bed label

* @return the index in the bed array corresponding to the provided label

*/

private int externalToInternalIndex(int bedLabel){

return bedLabel - minBedLabel;

}

/**

* Return the external/user label of the bed corresponding to the internal index.

*

* @param arrayIndex an index for the array of beds

* @return the bed label corresponding to the provided index

*/

private int internalToExternalLabel(int arrayIndex) {

return arrayIndex + minBedLabel;

}

/**

* Is the specified bed occupied?

*

* @param bedLabel a bed label

* @return whether or not the bed corresponding to the provided label is occupied by a patient

*/

public boolean isOccupied(int bedLabel) {

return beds.get(bedLabel)!=null;

}

/**

* Assign the specified person to the specified bed.

*

* @param p the person to assign to a bed

* @param bedLabel a bed label

*/

public void assignPatientToBed(Person p, int bedLabel) {

Bed b=new Bed();

b.patient=p;

beds.add(externalToInternalIndex(bedLabel), b);

}

/**

* Return the person in the specified bed.

*

* @param bedLabel a bed label

* @return the person that is assigned to the bed cooresponding to the provided bed label

*/

public Person getPatient(int bedLabel) {

return beds.get(externalToInternalIndex(bedLabel)).patient;

}

/**

* Return a String representation of the properties of the ward.

*

* @return a String representation of the ward

*/

public String toString()

{

String result = " Ward " + name + " with capacity " + length + " has the following patients: ";

int i=0;

for (Bed bed : beds) {

result = result + " bed " + internalToExternalLabel(i) + ": ";

if (beds.get(i) != null)

result = result + beds.get(i).patient.getName();

i++;

}

return result + " ";

}

/**

* A method to test the class.

*/

public static void main(String[] args)

{

Ward w = new Ward("surgery", 200, 210);

/* Check the mapping of internal and external indices. */

Patient p = new Patient("Pete", 123456);

w.assignPatientToBed(p, 205);

p = new Patient("Sue", 654321);

w.assignPatientToBed(p, 202);

System.out.println(w);

}

}

// Bed.java

package dragon;

public class Bed {

String name;

String number;

Person patient;

}

//Patient.java

package dragon;

import java.util.LinkedList;

public class Patient extends Person{

String bedReference;

LinkedList doctors;

public Patient(String pName, int pNumber) {

super(pName, pNumber);

this.doctors = new LinkedList();

}

public String getBedReference() {

return bedReference;

}

public void setBedReference(String bedReference) {

this.bedReference = bedReference;

}

public LinkedList getDoctors() {

return doctors;

}

public void setDoctors(LinkedList doctors) {

this.doctors = doctors;

}

@Override

public String toString() {

String text="";

if(bedReference!=null) {

text+="Patient: "+this.getName()+" Health number: "+this.getHealthNumber()+" Bed reference: "+this.getBedReference();

if(!doctors.isEmpty()) {

text+=" Doctors: ";

for (Person person : doctors) {

text+="\t"+person.getName()+" ";

}

}

} else {

text+="Patient: "+this.getName()+" Health number: "+this.getHealthNumber();

if(!doctors.isEmpty()) {

text+=" Doctors: ";

for (Person person : doctors) {

text+="\t"+person.getName()+" ";

}

}

}

return text;

}

public static void main(String[] args) {

Patient patient =new Patient("Aabid", 90);

Doctor doctor=new Doctor("Hilal", "dentist");

Doctor doctor1=new Doctor("Nasir", "General");

Doctor doctor2=new Doctor("Aadil", "Ortho");

Doctor doctor3=new Doctor("Saima", "Fake");

LinkedList docList=new LinkedList();

docList.add(doctor);

docList.add(doctor1);

docList.add(doctor2);

docList.add(doctor3);

patient.setDoctors(docList);

patient.setBedReference("34");

System.out.println(patient);

}

}

HospitalSystem class: The last class to write is one to run a simple hospital system. To keep it simple, the system will have only one ward. The class should also have two methods: one to return all the patient objects known to the system, and the other to return all the doctor objects known to the system. Both methods may return a dictionary where the key for patients is their health number, and for Doctors, their name. When the system starts, there are no patients and no doctors. Also at the start, the name of the ward, and the integer number of beds should be read 2 into the system in order to initialize the ward. During the running of the system, the system should display a message to the user for the user to select a task. When a task is selected, it should be carried out, and then another task selected. It is easiest to handle task selection by numbering the tasks as in a menu and having the user enter an integer. Note that when a value is read using Scanner, other than by nextLine0, none the characters after the value are read. Thus, a subsequent nextLine0 read will read those following characters up to and including the next end-of-line character(s). Such a read often just reads end-of-line character(s) that mark the end of the line after the previous read, so that the nextLine0 method simply returns the empty string. It does not read the characters on the next line (which might be what was wanted), since it finds end-of-line characters first. So be careful, and use the debugger!! HospitalSystem class: The last class to write is one to run a simple hospital system. To keep it simple, the system will have only one ward. The class should also have two methods: one to return all the patient objects known to the system, and the other to return all the doctor objects known to the system. Both methods may return a dictionary where the key for patients is their health number, and for Doctors, their name. When the system starts, there are no patients and no doctors. Also at the start, the name of the ward, and the integer number of beds should be read 2 into the system in order to initialize the ward. During the running of the system, the system should display a message to the user for the user to select a task. When a task is selected, it should be carried out, and then another task selected. It is easiest to handle task selection by numbering the tasks as in a menu and having the user enter an integer. Note that when a value is read using Scanner, other than by nextLine0, none the characters after the value are read. Thus, a subsequent nextLine0 read will read those following characters up to and including the next end-of-line character(s). Such a read often just reads end-of-line character(s) that mark the end of the line after the previous read, so that the nextLine0 method simply returns the empty string. It does not read the characters on the next line (which might be what was wanted), since it finds end-of-line characters first. So be careful, and use the debugger

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Domain Transfer Learning With 3q Data Processing

Authors: Ahmed Atif Hussain

1st Edition

B0CQS1NSHF, 979-8869061805

More Books

Students also viewed these Databases questions