Task 3: Main Program
Create a main program class that:
Use arrays to store all of your Patient, Nurse, and Doctor objects.
You can generate names by randomly choosing a combination of first and last names from pre-set lists of possibilities.
Sample Names
Do not use input from System.in for any part of your program.
Use static methods as appropriate to organize your code.
Try to keep all output at the end of your program.
This is the Code I have right now.
public class Person {
/**
* This nodeCount generates the unique id
*/
private static int val=1;
/**
* Declaring instance variable id
*/
private int ID;
public String givenName;
public String surname;
/**
* Parameterized constructor
* @param iD
* @param givenName
* @param surname
*/
public Person(String givenName, String surname) {
this.ID = val;
val++;
this.givenName = givenName;
this.surname = surname;
}
/**
* @return the iD
*/
public int getID() {
return ID;
}
/**
* This Method will return GivenName
* @return the givenName
*/
public String getGivenName() {
return givenName;
}
/**
* This Method will set the givenName
* @param givenName
* the givenName to set
*/
public void setGivenName(String givenName) {
this.givenName = givenName;
}
/**
* This Method will return surname
* @return the surname
*/
public String getSurname() {
return surname;
}
/**
* This Method will set surName
* @param surname
* the surname to set
*/
public void setSurname(String surname) {
this.surname = surname;
}
/*
* This method will return the Information about the class
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return givenName + " " + surname + "(ID# " + ID + ")";
}
}
//Employee class
class Employee extends Person{
String unit;
protected int annualSalary;
//constructor
public Employee(String unit,String givenName,String surname)
{ /*this will call parent class constructor,
you can modify the syntax according to your Person class constructor*/
super(givenName,surname);
this.unit=unit;
}
//method getAnnualSalary()
public int getAnnualSalary()
{
return annualSalary;
}
}
//class Nurse
class Nurse extends Employee{
int SHIFT_A=1;
int SHIFT_B=2;
int SHIFT_C=3;
private int shift;
//constructor
public Nurse(String unit,String givenName,String surname)
{ /*this will call parent class constructor, to initialization
of variable */
super(unit,givenName,surname);
shift=SHIFT_A;
//set default annualSalary
super.annualSalary=80000;
}
//setShift() method
public void setShift(int shift)
{
this.shift=shift;
if(shift==SHIFT_A)
super.annualSalary=80000;
else if(shift==SHIFT_B)
super.annualSalary=85000;
else
super.annualSalary=90000;
}
/*Overriding of toString() method there is some changes in structure
because i can't understand ID# 1234 meaning because it is not given */
public String toString() {
return String.format(super.givenName+" "+super.surname + "("+super.unit+" unit,shift "+this.shift +")");
}
public int getShift()
{
return this.shift;
}
}
//Doctor class
class Doctor extends Employee
{
String specialty;
//constructor
public Doctor(String unit,String specialty,String givenName,String surname)
{ //call parent class constructor
super(unit,givenName,surname);
this.specialty=specialty;
//set annualSalary
super.annualSalary=250000;
}
/*Overriding of toString() method there is some changes in structure
because i can't understand ID# 1234 meaning because it is not given */
public String toString() {
return String.format("Dr. "+super.givenName+" "+super.surname+"("+this.specialty+")");
}
}
//class Patient
class Patient extends Person
{
Doctor physician;
public Patient(String givenName,String surname,Doctor physician)
{/*call parent class constructor
you can modify this because parent class is not given*/
super(givenName,surname);
this.physician=physician;
}
}Screenshot
![7 9 12 13 3 import java.util. Random; 40 /* <terminated> Hospital Test [Java Application] C:\Program Files\Javajr 5 * Test cl](http://img.homeworklib.com/questions/6da128e0-1514-11ec-9f41-9b706fa2ec8b.png?x-oss-process=image/resize,w_560)
Program
HospitalTest.java
import java.util.Random;
/*
* Test class
*/
public class HospitalTest {
public static void main(String[] args) {
//Creates three or more Nurse
instances assigned to different shifts.
Nurse nurses[]=new Nurse[3];
nurses[0]=new
Nurse("Unit1","Nurse1","hNurse");
nurses[0].setShift(1);
nurses[1]=new
Nurse("Unit2","Nurse2","mNurse");
nurses[1].setShift(2);
nurses[2]=new
Nurse("Unit3","Nurse3","jNurse");
nurses[2].setShift(3);
//Creates three or more Doctor
instances.
Doctor doctors[]=new
Doctor[3];
doctors[0]=new
Doctor("Unit1","Peadeatric","Doctor1","hDoctor");
doctors[1]=new
Doctor("Unit2","Surgen","Doctor2","mDoctor");
doctors[2]=new
Doctor("Unit4","Ortho","Doctor3","jDoctor");
//Creates three or more Patient
instances with pre-determined names and
//manually assigned physicians
chosen from the pool of Doctor instances previously created.
Patient p1=new
Patient("Patient1","P1",doctors[0]);
Patient p2=new
Patient("Patient2","P2",doctors[1]);
Patient p3=new
Patient("Patient3","P3",doctors[2]);
//Create an array of 20 patients
randomly
Patient patients[]=new
Patient[20];
addPatients(patients,doctors);
//Prints the toString() values for
all employees.
System.out.println("All
employees");
for(int
i=0;i<doctors.length;i++) {
System.out.println(doctors[i]);
}
for(int i=0;i<nurses.length;i++)
{
System.out.println(nurses[i]);
}
//Calculates and prints the total
annual cost to employ all of the created doctors and nurses.
System.out.println("\nTotal annual
cost = $"+totalSalary(doctors,nurses)+"\n");
//Calculates and prints the number
of patients assigned to each Doctor.
listPatients(patients,doctors);
}
//Add 20 patients
public static void addPatients(Patient[]
patients,Doctor[] doctors) {
for(int
i=0;i<patients.length;i++) {
int index=new
Random().nextInt(doctors.length);
patients[i]=new
Patient("Patient"+(i+1),"P"+(i+1),doctors[index]);
}
}
//Calculate total cost of employees
public static int totalSalary(Doctor[] doctors,Nurse[]
nurses) {
int totalSal=0;
for(int
i=0;i<doctors.length;i++) {
totalSal+=doctors[i].getAnnualSalary();
}
for(int i=0;i<nurses.length;i++)
{
totalSal+=nurses[i].getAnnualSalary();
}
return totalSal;
}
//List doctorwise patients
public static void listPatients(Patient[]
patients,Doctor[] doctors) {
int j=0;
while(j<doctors.length) {
System.out.println(doctors[j]+" Patient INFO:");
for(int
i=0;i<patients.length;i++) {
if(patients[i].physician==doctors[j]) {
System.out.println(patients[i]);
}
}
System.out.println();j++;
}
}
}
Output
All employees
Dr. Doctor1 hDoctor(Peadeatric)
Dr. Doctor2 mDoctor(Surgen)
Dr. Doctor3 jDoctor(Ortho)
Nurse1 hNurse(Unit1 unit,shift 1)
Nurse2 mNurse(Unit2 unit,shift 2)
Nurse3 jNurse(Unit3 unit,shift 3)
Total annual cost = $1005000
Dr. Doctor1 hDoctor(Peadeatric) Patient INFO:
Patient4 P4(ID# 13)
Patient5 P5(ID# 14)
Patient7 P7(ID# 16)
Patient8 P8(ID# 17)
Patient9 P9(ID# 18)
Patient11 P11(ID# 20)
Patient12 P12(ID# 21)
Patient14 P14(ID# 23)
Dr. Doctor2 mDoctor(Surgen) Patient INFO:
Patient1 P1(ID# 10)
Patient3 P3(ID# 12)
Patient6 P6(ID# 15)
Patient10 P10(ID# 19)
Patient13 P13(ID# 22)
Patient15 P15(ID# 24)
Dr. Doctor3 jDoctor(Ortho) Patient INFO:
Patient2 P2(ID# 11)
Patient16 P16(ID# 25)
Patient17 P17(ID# 26)
Patient18 P18(ID# 27)
Patient19 P19(ID# 28)
Patient20 P20(ID# 29)
Task 3: Main Program Create a main program class that: Creates three or more Nurse instances...
In Java Create a testing class that does the following to the given codes below: To demonstrate polymorphism do the following: Create an arraylist to hold 4 base class objects Populate the arraylist with one object of each data type Code a loop that will process each element of the arraylist Call the first ‘common functionality’ method Call the second ‘common functionality’ method Call the third ‘common functionality’ method Verify that each of these method calls produces unique results Call...
Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so they throw exceptions when the following errors occur. - The Employee class should throw an exception named InvalidEmployeeNumber when it receives an employee number that is less than 0 or greater than 9999. - The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift. - The ProductionWorker class should thrown anexception named InvalidPayRate when it receives a negative number...
Create a super class called Store which will have below member variables, constructor, and methods Member variables: - a final variable - SALES_TAX_RATE = 0.06 - String name; /** * Constructor:<BR> * Allows client to set beginning value for name * This constructor takes one parameter<BR> * Calls mutator method setName to set the name of the store * @param name the name of the store */ /** getName method * @return a String, the name of the store */...
Question: Write the Main class code for the following application. The first three classes are given below. Lottery This lottery app allows users to sign up for an account, choose a random number or two, and then win a certain amount of money if their chosen number matches the number that the game draws. The house keeps the cash proceeds if nobody wins. The app must repeatedly do the following: Allow the user to (1) Add Player Account (2) Play...
2. Given following Java program, convert to class diagram, create two instances of Employee, and initialize them with following values: For employee1, name – your friend’s name, salary = 30000, 8 hours and avail is false For employee2, name – your friend’s name, salary = 80000, 10 hours and avail is true public class Employee { private String name; private double salary ; private int hours ; private boolean avail ; public Employee (double r, double h, boolean hd) {...
Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...
Inheritance and Polymorphism (use Pet.java) You are given a class named Pet.java. Create two child classes named Cat.java and Dog.java. Cat.java should add attributes for color and breed. Dog.java should add attributes for breed and size (use String for small, medium, large). Add appropriate constructors, getter/setter methods and toString() methods. In a separate file named PetDriver.java, create a main. In the main, create an ArrayList of Pet. Add an instance of Cat and an instance of Dog to the ArrayList....
In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many people are served every year and the average price per person. code the constructor, accessors, mutators, toString and equals method of the new subclass; also code a method returning the average taxes per year. You also need to include a client class to test your code for both the parent class and the subclass. Code for Store below(Super class aka...
Rewrite following code down below using Factory Pattern. -------------------------Staff.java--------------------------- import java.util.*; public class Staff extends Employee { private int HourlyRate; /**Constructor Staff which initiates the values*/ public Staff() { super(); HourlyRate=0; } /**Overloaded constructor method * @param ln last name * @param fn first name * @param ID Employee ID * @param sex Sex * @param hireDate Hired Date * @param hourlyRate Hourly rate for the work...
1. Employees and overriding a class method The Java program (check below) utilizes a superclass named EmployeePerson (check below) and two derived classes, EmployeeManager (check below) and EmployeeStaff (check below), each of which extends the EmployeePerson class. The main program creates objects of type EmployeeManager and EmployeeStaff and prints those objects. Run the program, which prints manager data only using the EmployeePerson class' printInfo method. Modify the EmployeeStaff class to override the EmployeePerson class' printInfo method and print all the...