Question

In: Computer Science

The project description: As a programmer, you have been asked to write a Java application, using...

The project description: As a programmer, you have been asked to write a Java application, using OOP concepts, for a Hospital with the following requirements: • The Hospital has several employees and each one of them has an ID (int), name (string), address (string), mobile phone number (string), email (string) and salary (double) with suitable data types. • The employees are divided into: o Administration staff: who have in addition to the previous information their position (string). o Doctor: who have also a rank (string) and specialty (string). The project requirements: • You will need to create all the needed Java classes with all the required information. • You have to apply all the OOP (Object Oriented Programming) concepts that we have covered in this module (i.e. inheritance, polymorphism, interface and collections) • Include a Microsoft Word document (name it as readme.doc) that includes several screenshots of your Netbeans IDE application GUI interface as well as the output screenshot results. Provide all assumptions that you have made during design and implementation. • Include the whole Netbeans Java project with all source codes. Write as much comments as possible to document your source codes. At the end, you will need to create a testing class (e.g. Hospital.java) with the static main() method with the following requirements: • It must have initial fixed collections of working staff (at least 3 administration staffs and 2 doctors) • The program will print a selection screen where the user can choose the operation he/she wants to perform. The selection screen will be repeated after each selection until the staff type the number 4 to completely exit from the program: 1. Add an administration staff (by providing all her/his information) to the list of all administration staff 2. Add a doctor (by providing all her/his information) to the list of all doctors 3. Print all working staff (remember to differentiate between administration staff and doctors in the output printout 4. Exit the program

Solutions

Expert Solution

//Hospital Application using Java (To demonstrate Object Oriented Programming concepts)

Folders/Files Structure

=================

########################################################################################

Employee.java

============

package com.test;

/**
* @author user
*
*         This is Employee class it is super class for AdministrativeStaff
*         class and Doctor class
*/
public class Employee {
   /*
   * id is an integer type variable, holds id of the employee name is a String
   * type,holds name of the employee address is a String type,holds address of
   * the employee mobileNumber is a String type,holds mobile number of the
   * Employee email is a String type,holds email of the Employee salary is a
   * String type, holds salary of the Employee
   */
   public int id;
   public String name;
   public String address;
   public String mobileNumber;
   public String email;
   public double salary;

   /*
   * This is 6 argument Employee constructor and it will initialize all the
   * instance variables of Employee class
   */
   public Employee(int id, String name, String address, String mobileNumber, String email, double salary) {
       this.id = id;
       this.name = name;
       this.address = address;
       this.mobileNumber = mobileNumber;
       this.email = email;
       this.salary = salary;
   }

   /*
   * getId() is a getter method and it will return id
   */
   public int getId() {
       return id;
   }

   /*
   * setId() is a setter method and it will modify the id
   */
   public void setId(int id) {
       this.id = id;
   }

   /*
   * getName() is a getter method and it will return name
   */
   public String getName() {
       return name;
   }

   /*
   * setName() is a setter method and it will modify the name
   */
   public void setName(String name) {
       this.name = name;
   }

   /*
   * getAddress() is a getter method and it will return address
   *
   **/
   public String getAddress() {
       return address;
   }

   /*
   * setAddress() is a setter method and it will modify the address
   */
   public void setAddress(String address) {
       this.address = address;
   }

   /*
   * getMobileNumber() is a getter method and it will return mobileNumber
   */

   public String getMobileNumber() {
       return mobileNumber;
   }

   /*
   * setMobileNumber() is a setter method and it will modify the mobileNumber
   */
   public void setMobileNumber(String mobileNumber) {
       this.mobileNumber = mobileNumber;
   }

   /*
   * getEmail() is a getter method and it will return email
   */
   public String getEmail() {
       return email;
   }

   /*
   * setEmail() is a setter method and it will modify the email
   */
   public void setEmail(String email) {
       this.email = email;
   }

   /*
   * getSalary() is a getter method and it will return salary
   */
   public double getSalary() {
       return salary;
   }

   /*
   * setSalary() is a setter method and it will modify the salary
   */
   public void setSalary(double salary) {
       this.salary = salary;
   }

}


#############################################################################

AdministrativeStaff.java

==================

package com.test;

/**
* This is AdministrativeStaff class
*/
public class AdministrativeStaff extends Employee {

   /*
   * position is a String type, holds position of the staff
   */
   public String position;

   /*
   * getPosition() is a getter method and it will return position
   */
   public String getPosition() {
       return position;
   }

   /*
   * setPosition() is a setter method and it will update position
   */
   public void setPosition(String position) {
       this.position = position;
   }

   /*
   * This 7 argument constructor and it will initialize the all the instance
   * variables of the AdministrativeStaff class
   */
   public AdministrativeStaff(int id, String name, String address, String mobileNumber, String email, double salary,
           String position) {
       // We are calling super class constructor
       super(id, name, address, mobileNumber, email, salary);
       this.position = position;
   }

}

######################################################################

Doctor.java

========

package com.test;
/*
* This is Doctor class
* */

public class Doctor extends Employee {
   /*
   * rank is a String type, holds rank of the Doctor speciality is a String
   * type,holds speciality of the Doctor
   */
   public String rank;
   public String speciality;

   /*
   * This is 8 argument constructor and it will initialize all the instance
   * variables of Doctor class
   */
   public Doctor(int id, String name, String address, String mobileNumber, String email, double salary, String rank,
           String speciality) {
       // we are calling super class constructor
       super(id, name, address, mobileNumber, email, salary);
       this.rank = rank;
       this.speciality = speciality;
   }

   /*
   * getRank() is a getter method and it will return rank
   */
   public String getRank() {
       return rank;
   }

   /*
   * setRank() is a setter method and it will update the rank
   */
   public void setRank(String rank) {
       this.rank = rank;
   }

   /*
   * getSpeciality() is a getter method and it will return speciality
   */
   public String getSpeciality() {
       return speciality;
   }

   /*
   * setSpeciality() is a setter method and it will update the speciality
   */
   public void setSpeciality(String speciality) {
       this.speciality = speciality;
   }

}

###################################################################

Hospital.java

=============

package com.test;

/**
* This is Hospital class( main class)
* */
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Hospital {

   public static void main(String[] args) {
       // Creating Scanner class object to get/read the data from keyboard
       Scanner sc = new Scanner(System.in);

       // Creating List Object to hold the Employee Objects
       List<Employee> workingStaff = new ArrayList<>();
       /*
       * creating 5 Hospital Staff Objects i.e. 3 AdministrativeStaff Objects
       * and 2 Doctor Objects and Added into list Object.(workingStaff)
       */
       Employee emp = new AdministrativeStaff(101, "AAA", "Hyderabad", "9999", "[email protected]", 20000.00, "Admin");
       workingStaff.add(emp);
       emp = new AdministrativeStaff(102, "BBB", "Hyderabad", "8888", "[email protected]", 30000.00, "HR");
       workingStaff.add(emp);
       emp = new AdministrativeStaff(103, "CCC", "Hyderabad", "7777", "[email protected]", 10000.00, "Driver");
       workingStaff.add(emp);
       emp = new Doctor(1001, "DDD", "Hyderabad", "6666", "[email protected]", 50000.00, "Senior", "Cardiologist");
       workingStaff.add(emp);
       emp = new Doctor(1002, "EEE", "Hyderabad", "5555", "[email protected]", 60000.00, "Junior", "Dermatologist");
       workingStaff.add(emp);

       /*
       * Recursively we are displaying the Menu options for User selection
       */
       while (true) {
           System.out.println("1.Add an administration staff");
           System.out.println("2.Add an doctor");
           System.out.println("3.Print all working staff");
           System.out.println("4.Exit");
           System.out.println("Enter your choice:");
           int choice = sc.nextInt();
           int id;
           String name;
           String address;
           String mobileNumber;
           String email;
           double salary;
           String position;
           String rank;
           String speciality;

           switch (choice) {
           case 1:
               // Reading the Administrative staff details
               System.out.println("Enter Administration staff details");
               System.out.println("Enter staff id");
               id = sc.nextInt();
               System.out.println("Enter staff name");
               name = sc.next();
               System.out.println("Enter staff address");
               address = sc.next();
               System.out.println("Enter staff mobile Number");
               mobileNumber = sc.next();
               System.out.println("Enter staff email");
               email = sc.next();
               System.out.println("Enter staff salary");
               salary = sc.nextDouble();
               System.out.println("Enter staff position");
               position = sc.next();
               // creating AdministraveStaff object by passing all the required
               // details
               emp = new AdministrativeStaff(id, name, address, mobileNumber, email, salary, position);
               // adding emp object to List object
               workingStaff.add(emp);
               break;
           case 2:
               // Reading doctor details from keyboard
               System.out.println("Enter Doctor details");
               System.out.println("Enter doctor id");
               id = sc.nextInt();
               System.out.println("Enter doctor name");
               name = sc.next();
               System.out.println("Enter doctor address");
               address = sc.next();
               System.out.println("Enter doctor mobile Number");
               mobileNumber = sc.next();
               System.out.println("Enter doctor email");
               email = sc.next();
               System.out.println("Enter doctor salary");
               salary = sc.nextDouble();
               System.out.println("Enter doctor rank");
               rank = sc.next();
               System.out.println("Enter doctor speciality");
               speciality = sc.next();
               // Creating doctor object by passing required details
               emp = new Doctor(id, name, address, mobileNumber, email, salary, rank, speciality);
               // Adding emp Object to List object
               workingStaff.add(emp);
               break;

           case 3:
               // Printing all staff details and differentiating
               // AdministrativeStaff and Doctor
               for (Employee employee : workingStaff) {
                   if (employee instanceof AdministrativeStaff) {
                       System.out.println("****Administrative staff***");
                       System.out.println("Id:" + employee.getId());
                       System.out.println("Name:" + employee.getName());
                       System.out.println("Address :" + employee.getAddress());
                       System.out.println("Mobile Number: " + employee.getMobileNumber());
                       System.out.println("Email : " + employee.getEmail());
                       System.out.println("Salary :" + employee.getSalary());
                       System.out.println("Position :" + ((AdministrativeStaff) employee).getPosition());
                   } else {
                       System.out.println("****Docotor****");
                       System.out.println("Id:" + employee.getId());
                       System.out.println("Name:" + employee.getName());
                       System.out.println("Address :" + employee.getAddress());
                       System.out.println("Mobile Number: " + employee.getMobileNumber());
                       System.out.println("Email : " + employee.getEmail());
                       System.out.println("Salary :" + employee.getSalary());
                       System.out.println("Rank :" + ((Doctor) employee).getRank());
                       System.out.println("Speciality :" + ((Doctor) employee).getSpeciality());
                   }
               }

               break;

           case 4:
               // Exiting/Terminating from the loop
               System.exit(0);

           }

       }

   }

}


#############################################

Test Results/ output

=================

Note:

Please let me know if you have any doubts/concerns


Related Solutions

As a programmer, you have been asked to write a Java application, using OOP concepts, for...
As a programmer, you have been asked to write a Java application, using OOP concepts, for a Hospital with the following requirements: • The Hospital has several employees and each one of them has an ID (int), name (string), address (string), mobile phone number (string), email (string) and salary (double) with suitable data types. • The employees are divided into: o Administration staff: who have in addition to the previous information their position (string). o Doctor: who have also a...
As a programmer in a java project, you have been asked by your project manager to...
As a programmer in a java project, you have been asked by your project manager to describe the most efficient way to store the following assigned numbers 10,20,30,1000,200,350 for an operation which involves on calculation such as sum and average.
JAVA - The Westfield Carpet Company has asked you to write an application that calculates the...
JAVA - The Westfield Carpet Company has asked you to write an application that calculates the price of carpeting for rectangular rooms. To calculate the price, you multiply the area of the floor(width times length) by the price per square foot of carpet. For example, the area of floor that is 12 feet long and 10 feet wide is 120 square feet. To cover that floor with carpet that costs $8 per square foot would cost $960. (12 X 10...
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, balance inquiries, close accounts, etc.. Initially, the account information of existing customers is to be read into an array of BankAccount objects. The private data members of the BankAccount Class will include: first...
Create a project plan on the game or application you are creating. Using java programming. The...
Create a project plan on the game or application you are creating. Using java programming. The project plan should include the following: A description of the game or application The IDE or game engine your plan to use to create the game or app and information on how you are going to develop the game or app If you choose to create a game, how are you going to approach the game design and game development process or if you...
This is a Java program Problem Description Write an application that inputs five digits from the...
This is a Java program Problem Description Write an application that inputs five digits from the user, assembles the individual digits into a five-digit integer number (the first digit is for one’s place, the second digit is for the ten’s place, etc.) using arithmetic calculations and prints the number. Assume that the user enters enough digits. Sample Output Enter five digits: 1 2 3 4 5 The number is 54321 Problem-Solving Tips The input digits are integer, so you will...
You have been asked to calculate the WACC for a new project and you have decided...
You have been asked to calculate the WACC for a new project and you have decided to use the pure play method. You determine the capital structure is 75% equity and 25% debt (i.e., E/(D+E) = 0.75). To get the cost of debt for the project you plan to use an annual bond with the following characteristics: Price is $1,000, Coupon rate is 5%, face value is $1,000 and it has 10 years to maturity. To get the cost of...
Having trouble getting started on this Overview As a programmer, you have be asked by a...
Having trouble getting started on this Overview As a programmer, you have be asked by a good friend to create a program that will allow them to keep track of their personal expenses. They want to be able to enter their expenses for the month, store them in a file, and then have the ability to retrieve them later. However, your friend only wants certain people to have the ability to view his or her expenses, so they are requesting...
QUESTION 2 You are developing an online quiz web application and you have been asked to...
QUESTION 2 You are developing an online quiz web application and you have been asked to design a JSON file for creating a TestBank. You need to design the JSON file for storing some multiple choice questions/answers. Here is an example of sample data which you need to convert it into JSON Q) 5 + 7 * 2 = ? a) 14 b) 12 c) 24 d) 19 ANS: d Answer the following questions: 1) How do you design the...
You have been asked to explain how the time value of money affects the application of...
You have been asked to explain how the time value of money affects the application of the Federal unified transfer taxes for a presentation at your school's homecoming seminar. To help you prepare for the presentation, select either "Yes" or "No" to indicate how the time value of money affects the application of the Federal unified transfer taxes. a. The Federal unified transfer tax system is unified and cumulative in effect. b. Gift tax liability incurred represents a postpayment of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT