In: Computer Science
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
//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