Question

Task 3: Main Program Create a main program class that: Creates three or more Nurse instances...

Task 3: Main Program

Create a main program class that:

  1. Creates three or more Nurse instances assigned to different shifts.
  2. Creates three or more Doctor instances.
  3. Creates three or more Patient instances with pre-determined names and manually assigned physicians chosen from the pool of Doctor instances previously created.
  4. Generates another 20 Patient instances using randomly generated names and randomly assigns them physicians chosen from the pool of Doctor instances previously created.
  5. Prints the toString() values for all employees.
  6. Prints the toString() value and physician ID for each patient.
  7. Calculates and prints the total annual cost to employ all of the created doctors and nurses.
  8. Calculates and prints the number of patients assigned to each Doctor.

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;
    }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

7 9 12 13 3 import java.util. Random; 40 /* <terminated> Hospital Test [Java Application] C:\Program Files\Javajr 5 * Test cl

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)

Add a comment
Know the answer?
Add Answer to:
Task 3: Main Program Create a main program class that: Creates three or more Nurse instances...
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
  • In Java Create a testing class that does the following to the given codes below: To...

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

  • Create a super class called Store which will have below member variables, constructor, and methods Member...

    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 */...

  • 1. Employees and overriding a class method The Java program (check below) utilizes a superclass named...

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

  • Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...

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

  • Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so...

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

  • In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following...

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

  • (JAVA NetBeans) Write programs in java Example 10.21-24 //Animal.java /** Animal class * Anderson. Franceschi */...

    (JAVA NetBeans) Write programs in java Example 10.21-24 //Animal.java /** Animal class * Anderson. Franceschi */ import java.awt.Graphics; public abstract class Animal { private int x; // x position private int y; // y position private String ID; // animal ID /** default constructor * Sets ID to empty String */ public Animal( ) { ID = ""; } /** Constructor * @param rID Animal ID * @param rX x position * @param rY y position */ public Animal( String...

  • Use inheritance to create a new class AudioRecording based on Recording class that: it will retain...

    Use inheritance to create a new class AudioRecording based on Recording class that: it will retain all the members of the Recording class, it will have an additional field bitrate (non-integer numerical; it cannot be modified once set), its constructors (non-parametrized and parametrized) will set all the attributes / fields of this class (reuse code by utilizing superclass / parent class constructors): Non-parametrized constructor should set bitrate to zero, If arguments for the parametrized constructor are illegal or null, it...

  • Java Create four classes: 1.      An Animal class that acts as a superclass for Dog and...

    Java Create four classes: 1.      An Animal class that acts as a superclass for Dog and Bird 2.      A Bird class that is a descendant of Animal 3.      A Dog class that is a descendant of Animal 4.      A “driver” class named driver that instantiates an Animal, a Dog, and a Bird object. The Animal class has: ·        one instance variable, a private String variable named   name ·        a single constructor that takes one argument, a String, used to set...

  • 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...

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