Question

The project description As a programmer; you have been asked to write a program for a Hospital with the following The Hospita program Java oop
0 0
Add a comment Improve this question Transcribed image text
Answer #1

################## Employee.java ############
package hospital;

/**
* The Class Employee.
*/
public abstract class Employee {

   /** The id. */
   private int id;

   /** The name. */
   private String name;

   /** The address. */
   private String address;

   /** The mobile number. */
   private int mobileNumber;

   /** The salary. */
   private double salary;

   /** The email. */
   private String email;

   /**
   * Instantiates a new employee.
   *
   * @param id the id
   * @param name the name
   * @param address the address
   * @param mobileNumber the mobile number
   * @param salary the salary
   * @param email the email
   */
   public Employee(int id, String name, String address, int mobileNumber, double salary, String email) {
       this.id = id;
       this.name = name;
       this.address = address;
       this.mobileNumber = mobileNumber;
       this.salary = salary;
       this.email = email;
   }

   /**
   * Gets the id.
   *
   * @return the id
   */
   public int getId() {
       return id;
   }

   /**
   * Gets the name.
   *
   * @return the name
   */
   public String getName() {
       return name;
   }

   /**
   * Gets the address.
   *
   * @return the address
   */
   public String getAddress() {
       return address;
   }

   /**
   * Gets the mobile number.
   *
   * @return the mobile number
   */
   public int getMobileNumber() {
       return mobileNumber;
   }

   /**
   * Gets the salary.
   *
   * @return the salary
   */
   public double getSalary() {
       return salary;
   }

   /**
   * Gets the email.
   *
   * @return the email
   */
   public String getEmail() {
       return email;
   }

   @Override
   public String toString() {
       return String.format("Employee id: %s%n, Employee name: %s%n, Address: %s%n, Mobile Number: %s%n, Salary: $%s%n, Email: %s%n", id, name, address, mobileNumber, salary,
               email);
   }

}

################ AdministrationStaff.java #################
package hospital;

/**
* The Class AdministrationStaff.
*/
public class AdministrationStaff extends Employee {

   /** The position. */
   private String position;

   /**
   * Instantiates a new administration staff.
   *
   * @param id the id
   * @param name the name
   * @param address the address
   * @param mobileNumber the mobile number
   * @param salary the salary
   * @param email the email
   * @param position the position
   */
   public AdministrationStaff(int id, String name, String address, int mobileNumber, double salary, String email, String position) {
       super(id, name, address, mobileNumber, salary, email);
       this.position = position;
   }

   /**
   * Gets the position.
   *
   * @return the position
   */
   public String getPosition() {
       return position;
   }

   @Override
   public String toString() {
       return String.format("%s,Position: %s", super.toString(), position);
   }

}

################## Nurse.java ###############
package hospital;

/**
* The Class Nurse.
*/
public class Nurse extends Employee {

   /** The rank. */
   private String rank;

   /** The specialty. */
   private String specialty;

   /**
   * Instantiates a new nurse.
   *
   * @param id the id
   * @param name the name
   * @param address the address
   * @param mobileNumber the mobile number
   * @param salary the salary
   * @param email the email
   * @param rank the rank
   * @param specialty the specialty
   */
   public Nurse(int id, String name, String address, int mobileNumber, double salary, String email, String rank, String specialty) {
       super(id, name, address, mobileNumber, salary, email);
       this.rank = rank;
       this.specialty = specialty;
   }

   /**
   * Gets the rank.
   *
   * @return the rank
   */
   public String getRank() {
       return rank;
   }

   /**
   * Gets the specialty.
   *
   * @return the specialty
   */
   public String getSpecialty() {
       return specialty;
   }

   @Override
   public String toString() {
       return String.format("%s, Rank: %s%n, Specialty: %s", super.toString(), rank, specialty);
   }

}

######################### Doctor.java ################
package hospital;

/**
* The Class Doctor.
*/
public class Doctor extends Nurse {

   /** The special nurse. */
   private boolean specialNurse;

   /**
   * Instantiates a new doctor.
   *
   * @param id the id
   * @param name the name
   * @param address the address
   * @param mobileNumber the mobile number
   * @param salary the salary
   * @param email the email
   * @param rank the rank
   * @param specialty the specialty
   * @param specialNurse the special nurse
   */
   public Doctor(int id, String name, String address, int mobileNumber, double salary, String email, String rank, String specialty, boolean specialNurse) {
       super(id, name, address, mobileNumber, salary, email, rank, specialty);
       this.specialNurse = specialNurse;
   }

   /**
   * Gets the special nurse.
   *
   * @return the special nurse
   */
   public boolean getSpecialNurse() {
       return specialNurse;
   }

   @Override
   public String toString() {
       return String.format("%s,specialNurse: %s", super.toString(), specialNurse);
   }

}

################## Patient.java #############
package hospital;

import java.util.ArrayList;
import java.util.List;

public class Patient {
   /** The id. */
   private int id;

   /** The name. */
   private String name;

   /** The address. */
   private String address;

   /** The mobile number. */
   private int mobileNumber;

   /** The type. */
   private String type;

   /** The email. */
   private String email;

   private List<Service> services;

   public Patient(int id, String name, String address, int mobileNumber, String type, String email) {
       this.id = id;
       this.name = name;
       this.address = address;
       this.mobileNumber = mobileNumber;
       this.type = type;
       this.email = email;
       this.services = new ArrayList<>();
   }

   public int getId() {
       return id;
   }

   public String getName() {
       return name;
   }

   public String getAddress() {
       return address;
   }

   public int getMobileNumber() {
       return mobileNumber;
   }

   public String getType() {
       return type;
   }

   public String getEmail() {
       return email;
   }

   public List<Service> getServices() {
       return services;
   }

   public void addService(Service service) {
       services.add(service);
   }

   @Override
   public String toString() {
       return String.format("Patient id: %s%n, Patient name: %s%n, Address: %s%n, Mobile Number: %s%n, Type: $%s%n, Email: %s%n, Services: %s", id, name, address, mobileNumber,
               type, email, services.toString());
   }
}

#################### Service.java ################
package hospital;

/**
* The Class Service.
*/
public class Service {
   /** The id. */
   private int id;

   /** The name. */
   private String name;

   /** The price. */
   private double price;

   /**
   * Instantiates a new service.
   *
   * @param id the id
   * @param name the name
   * @param price the price
   */
   public Service(int id, String name, double price) {
       this.id = id;
       this.name = name;
       this.price = price;
   }

   /**
   * Gets the id.
   *
   * @return the id
   */
   public int getId() {
       return id;
   }

   /**
   * Gets the name.
   *
   * @return the name
   */
   public String getName() {
       return name;
   }

   /**
   * Gets the price.
   *
   * @return the price
   */
   public double getPrice() {
       return price;
   }

   @Override
   public String toString() {
       return String.format("Service id: %s, Service Name: %s, Price: $%s", id, name, price);
   }

}

################## Hospital.java #################
package hospital;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
* The Class Hospital.
*/
public class Hospital {

   /** The staffs. */
   List<Employee> staffs;

   /** The doctors. */
   List<Employee> doctors;

   /** The patients. */
   List<Patient> patients;

   /** The employee id. */
   private static int employeeId = 1;

   /** The patient id. */
   private static int patientId = 1;

   /** The service id. */
   private static int serviceId = 1;

   /**
   * Instantiates a new hospital.
   */
   public Hospital() {
       this.staffs = new ArrayList<>();
       this.doctors = new ArrayList<>();
       this.patients = new ArrayList<>();
       addStaffs();
       run();
   }

   /**
   * The main method.
   *
   * @param args the arguments
   */
   public static void main(String[] args) {
       new Hospital();
   }

   /**
   * Run.
   */
   private void run() {
       Scanner scan = new Scanner(System.in);
       int selection = 0;
       validateStaff(scan);
       do {
           printMenu();
           selection = scan.nextInt();
           switch (selection) {
           case 1:
               System.out.println("Enter Doctor Name: ");
               String docName = scan.next();
               System.out.println("Enter Doctor Address: ");
               String docAddress = scan.next();
               System.out.println("Enter Doctor Mobile number: ");
               int docMobileNo = scan.nextInt();
               System.out.println("Enter Doctor salary: ");
               double salary = scan.nextDouble();
               System.out.println("Enter Doctor email: ");
               String docEmail = scan.next();
               System.out.println("Enter Doctor Rank: ");
               String docRank = scan.next();
               System.out.println("Enter Doctor speciality: ");
               String docSpeciality = scan.next();
               System.out.println("Is special nurse required(Y/N): ");
               String nurseRequired = scan.next();
               boolean specialNurse;
               if (nurseRequired.equalsIgnoreCase("Y")) {
                   specialNurse = true;
               }
               else {
                   specialNurse = false;
               }
               doctors.add(new Doctor(employeeId++, docName, docAddress, docMobileNo, salary, docEmail, docRank, docSpeciality, specialNurse));
               break;
           case 2:
               System.out.println("Enter Patient Name: ");
               String patientName = scan.next();
               System.out.println("Enter Patient Address: ");
               String patientAddress = scan.next();
               System.out.println("Enter Patient Mobile number: ");
               int patientMobileNo = scan.nextInt();
               System.out.println("Enter Patient Type: ");
               String patientType = scan.next();
               System.out.println("Enter Patient email: ");
               String patientEmail = scan.next();
               patients.add(new Patient(patientId++, patientName, patientAddress, patientMobileNo, patientType, patientEmail));
               break;

           case 3:
               System.out.println("Enter patient Id: ");
               int pId = scan.nextInt();
               System.out.println("Enter Service Name: ");
               String serviceName = scan.next();
               System.out.println("Enter Service Price: ");
               double servicePrice = scan.nextDouble();
               Patient pat = findPatientById(pId);
               if (pat == null) {
                   System.out.println("Patient not found");
               }
               else {
                   if (pat.getType().equalsIgnoreCase("A")) {
                       servicePrice -= (servicePrice * 25) / 100;
                   }
                   pat.addService(new Service(serviceId++, serviceName, servicePrice));
               }
               break;

           case 4:
               System.out.println("Enter patient Id: ");
               int paId = scan.nextInt();
               double bill = 0;
               Patient pati = findPatientById(paId);
               if (pati == null) {
                   System.out.println("Patient not found");
               }
               else {
                   for (Service s : pati.getServices()) {
                       bill += s.getPrice();
                   }
               }
               System.out.println("Patient's Bill is $" + bill);
               break;

           case 5:
               System.out.println("Enter doc id:");
               int docId = scan.nextInt();
               Employee doc = findDoctorById(docId);
               if (doc == null) {
                   System.out.println("Doctor not found");
               }
               else {
                   System.out.println(doc.toString());
               }
               break;

           case 6:
               System.out.println("Enter patient Id: ");
               int patId = scan.nextInt();
               Patient patient = findPatientById(patId);
               if (patient == null) {
                   System.out.println("Patient not found");
               }
               else {
                   System.out.println(patient.toString());
               }
               break;

           case 7:
               break;

           default:
               System.out.println("Invalid Input. Please try again");
               break;
           }
       } while (selection != 7);

       scan.close();

   }

   /**
   * Find doctor by id.
   *
   * @param docId the doc id
   * @return the employee
   */
   private Employee findDoctorById(int docId) {
       for (Employee d : doctors) {
           if (d.getId() == docId) {
               return d;
           }
       }
       return null;
   }

   /**
   * Find patient by id.
   *
   * @param pId the id
   * @return the patient
   */
   private Patient findPatientById(int pId) {
       for (Patient p : patients) {
           if (p.getId() == pId) {
               return p;
           }
       }
       return null;
   }

   /**
   * Validate staff.
   *
   * @param scan the scan
   */
   private void validateStaff(Scanner scan) {
       boolean continueFlag = true;
       do {
           System.out.println("Enter your name: ");
           String staffName = scan.next();
           for (Employee e : staffs) {
               if (e.getName().equalsIgnoreCase(staffName)) {
                   continueFlag = false;
               }
           }
           if (continueFlag) {
               System.out.println("Staff not found. Please try again");
           }
       } while (continueFlag);
   }

   /**
   * Adds the staffs.
   */
   private void addStaffs() {
       staffs.add(new AdministrationStaff(employeeId++, "Pete", "NY", 8797638, 1000, "[email protected]", "admin"));
       staffs.add(new AdministrationStaff(employeeId++, "Sam", "NY", 8797338, 1000, "[email protected]", "Staff Admin"));
       staffs.add(new AdministrationStaff(employeeId++, "Gene", "NY", 87397638, 1000, "[email protected]", "Hospital Admin"));
   }

   /**
   * Prints the menu.
   */
   public void printMenu() {
       System.out.println("Please Select your choice or enter 7 to exit");
       System.out.println("1. Add Doctor");
       System.out.println("2. Add Patient");
       System.out.println("3. Add Service");
       System.out.println("4. Print the patient's bill");
       System.out.println("5. Print doctor information");
       System.out.println("6. Print patient information");
       System.out.println("7. Exit");
       System.out.println("Enter your selection: ");
   }
}

Add a comment
Know the answer?
Add Answer to:
The project description As a programmer; you have been asked to write a program for a Hospital wi...
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
  • program Java oop The project description As a programmer; you have been asked to write a...

    program Java oop The project description As a programmer; you have been asked to write a program for a Hospital with the following The Hospital has several employees and each one of them has an ID, name, address, mobile number, email and salary. . The employees are divided into Administration staff: who have in addition to the previous information their position. Nurse: who have their rank and specialty stored in addition to the previous o o Doctor: who have the...

  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

  • Description: You have been asked to help the College of IST Running Club by designing a...

    Description: You have been asked to help the College of IST Running Club by designing a program to help them keep track of runners in the club, the races that will occur, and each runner's performance in each race! Requirements: Please use Java to implement the program Your program must: Store information about each Runner. Store information about each Race. Store information about the performance of each runner in each race that they compete in. Note that each race may...

  • Make an ERD using the following description

    WardsThe Hope Hospital has 17 wards with a total of 240 beds available for short- and long-term patients, and an outpatient clinic. Each ward is uniquely identified by a number (for example, ward 11) and also a ward name (for example, Orthopedic), location (for example, E Block), total number of beds, and telephone extension number (for example, Extn. 7711).Staff The Hospital has a Medical Director, who has overall responsibility for the management of the hospital. The Medical Director maintains control...

  • You have been hired as a programmer by a major bank. Your first project is a...

    You have been hired as a programmer by a major bank. Your first project is a small banking transaction system. Each account consists of a number and a balance. The user of the program (the teller) can create a new account, as well as perform deposits, withdrawals, and balance inquiries. The application consists of the following functions:  N- New account  W- Withdrawal  D- Deposit  B- Balance  Q- Quit  X- Delete Account Use the following...

  • Write java program The purpose of this assignment is to practice OOP with Array and Arraylist,...

    Write java program The purpose of this assignment is to practice OOP with Array and Arraylist, Class design, Interfaces and Polymorphism. Create a NetBeans project named HW3_Yourld. Develop classes for the required solutions. Important: Apply good programming practices Use meaningful variable and constant names. Provide comment describing your program purpose and major steps of your solution. Show your name, university id and section number as a comment at the start of each class. Submit to Moodle a compressed folder of...

  • 1. A patient is concerned that his hospital records may have been inappropriately accessed by a...

    1. A patient is concerned that his hospital records may have been inappropriately accessed by a neighbor who is an employee of the organization. Which action should the nurse take first? Group of answer choices arrange for an audit to determine who has accessed this patient's record notify security and ask that they monitor all of the employee's activities confront the employee about the patient's concerns 2. The nurse asks the patient to sign a document acknowledging that some information...

  • You are asked to build and test the following system using Java and the object-oriented concepts ...

    You are asked to build and test the following system using Java and the object-oriented concepts you learned in this course: Project (20 marks) CIT College of Information technology has students, faculty, courses and departments. You are asked to create a program to manage all these information's. Create a class CIT to represents the following: Array of Students, each student is represented by class Student. Array of Faculty, each faculty is represented by class Faculty. Array of Course, each course...

  • write in java code. oop. i dont have its written code. i have its output in...

    write in java code. oop. i dont have its written code. i have its output in the thrid picture and how the inheritance works with the second picture. just need it in full written code and uni class will be. jus need you to write the whole code for me as its an extra question which i need for my preparation of my exam. add as you but it must be correct and similar to the question Inheritance Do the...

  • Assume that you are working with a hospital and this hospital needs a software system to...

    Assume that you are working with a hospital and this hospital needs a software system to track its patients’ information. Your role in this software development is to design the database. There are many aspects of such a hospital software system to develop. However, in this assignment, you will only address interactions between doctors and patients. Your first step will be to create the relations necessary for this system and identify and describe the constraints that would be appropriate for...

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