Lavi M.

asked • 11/22/20

Can someone fix my code based on my comment under this question? *java*

My code:


package javaapplication45;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class JavaApplication45 {

// Maain Class

public static void main(String[] args){

Scanner input =new Scanner(System.in);

// Menu

Hospital h1= new Hospital("ALnoor Hospital");

System.out.println("1-Add a administration ");

System.out.println("2-Add a doctor ");

System.out.println("3-Print all working staff ");

System.out.println("4-Exit the program");

System.out.println("pick a choice:");

// input from user

int choice = input.nextInt();

while(choice!=4){// Choice 1

System.out.println("Enter your choice:");choice = input.nextInt();

EmployeeAdmin O1 = new EmployeeAdmin(32465,"Majid Al-Shami\n","1035 W. Rayen Ave Youngstown OH 44512\n","599-513-8742\n","mmaa04@gmail.com\n",53612.95,"Production Manager\n\n");

EmployeeAdmin O2 = new EmployeeAdmin(7111,"Naser Amari\n","39960 Winding Creek Lane Warren OH 44486\n","507-215-8947\n","nassers87@yahoo.com\n",102436.98,"Inventory Management\n\n");

EmployeeAdmin O3 = new EmployeeAdmin(24576,"Nader Abadi\n","1747 Tarah Trace Dr Youngstown OH 44512\n","566-536-8911\n","abadi37569@gmail.com\n",65432.10,"Software\n\n\n");

EmployeeAdmin O4 = new EmployeeAdmin(12345,"Najjar Bin Baz\n","9756 Lake Worthington Rd Beloit OH 43210\n","533-586-4321\n","najjarbb66@gmail.com\n",76543.21,"Project Management\n\n");

if(choice==1){System.out.println("Enter Admin ID:");

int AID=input.nextInt();

System.out.println("Enter Admin NAME:");

String ANAME= input.next()+"\n";

System.out.println("Enter Admin ADDRESS:");

String AADDRESS=input.next()+"\n";

System.out.println("Enter Admin PHONE:");

String APHONE=input.next()+"\n";

System.out.println("Enter Admin EMAIL:");

String AEMAIL=input.next()+"\n";

System.out.println("Enter Admin SALARY:");

long ASALARY=input.nextLong();

System.out.println("Enter Admin POSITION:");

String APOSITION=input.next()+"\n";

EmployeeAdmin O5 = new EmployeeAdmin(AID,ANAME,AADDRESS,APHONE,AEMAIL,ASALARY,APOSITION);

h1.addEmployeeAdmin(O5);

System.out.println(h1.showEmployeeAdmin());}

if(choice==2){// Choice 2

System.out.println("Enter Doctor ID:");

int DID=input.nextInt();

System.out.println("Enter Doctor NAMR:");

String DNAME= input.next()+"\n";

System.out.println("Enter Doctor ADDRESS:");

String DADDRESS=input.next()+"\n";

System.out.println("Enter Doctor PHONE:");

String DPHONE=input.next()+"\n";

System.out.println("Enter Doctor EMAIL:");

String DEMAIL=input.next()+"\n";

System.out.println("Enter Doctor SALARY:");

long DSALARY=input.nextLong();

System.out.println("Enter Doctor RANK:");

String DRANK=input.next()+"\n";

System.out.println("Enter Doctor SPECIALTY:");

String DSPRCIALTY=input.next()+"\n";

Doctor D5 = new Doctor(DID,DNAME,DADDRESS,DPHONE,DEMAIL,DSALARY,DRANK,DSPRCIALTY);

h1.addDoctor(D5);

System.out.println(h1.showDoctors());}

if(choice==3){// Choice 3

EmployeeAdmin o1 = new EmployeeAdmin(32465,"Majid Al-Shami\n","1035 W. Rayen Ave Youngstown OH 44512\n","599-513-8742\n","mmaa04@gmail.com\n",53612.95,"Production Manager\n\n");

EmployeeAdmin o2 = new EmployeeAdmin(7111,"Naser Amari\n","39960 Winding Creek Lane Warren OH 44486\n","507-215-8947\n","nassers87@yahoo.com\n",102436.98,"Inventory Management\n\n");

EmployeeAdmin o3 = new EmployeeAdmin(24576,"Nader Abadi\n","1747 Tarah Trace Dr Youngstown OH 44512\n","566-536-8911\n","abadi37569@gmail.com\n",65432.10,"Software\n\n\n");

EmployeeAdmin o4 = new EmployeeAdmin(12345,"Najjar Bin Baz\n","9756 Lake Worthington Rd Beloit OH 43210\n","533-586-4321\n","najjarbb66@gmail.com\n",76543.21,"Project Management\n\n");

h1.addEmployeeAdmin(o1);

h1.addEmployeeAdmin(o2);

h1.addEmployeeAdmin(o3);

h1.addEmployeeAdmin(o4);

System.out.println(h1.showEmployeeAdmin());

Doctor d1 = new Doctor(12346,"Awad Al-Quraishi\n","234 Meribal Rd. Cranstow OH 44412\n","545-146-5789\n","aaa993@yahoo.com\n",245132.56,"Clinic\n","Phsychiatric\n\n");

Doctor d2 = new Doctor(12347,"Attia Al-Masih\n","1854 Sheridan St. Warren OH 44483\n","555-123-9876\n","attia332266@gmail.com\n",189234.56,"Electrolysis\n","Electrolysis\n\n");

Doctor d3 = new Doctor(12348,"Khalid Maalouf\n","34 Western Reserve Rd North Lima OH 44382\n","581-418-2975\n","khaloodie77nn@yahoo.com\n",166240.87,"General\n","Pediatrics\n\n");

Doctor d4 = new Doctor(12349,"Hajjar Haddad\n","2930 SR 46 Niles OH 44486\n","530-215-9867\n","hh44hajarhaddad66@gmail.com\n",213456.78,"MED3","Internal Med\n\n");

h1.addDoctor(d1);

h1.addDoctor(d2);

h1.addDoctor(d3);

h1.addDoctor(d4);

System.out.println(h1.showDoctors());}}

System.out.println("Exit Program");// Choice 4

}}

//******** Employee.java *******************************

class Employee{

// private instance variables

private int employeeID;// Employee's id

private String employeeName;// Employee's name

private String employeeAddress;// Employee's address

private String employeePhone;// Employee's phone

private String employeeEmail;// Employee's email

private double employeeSalary;// Employee's salary

//Constructor

public Employee(int id, String name, String addr, String ph, String email, double salary){

employeeID = id;employeeName = name;employeeAddress = addr;employeePhone = ph;employeeEmail =email;employeeSalary = salary;}

// Public methods

// Getters and Setters

public void SetName(String name) { employeeName =name; }// Sets name

public void SetAddress(String addr) { employeeName =addr; }// Sets address

public void SetPhone(String ph) { employeePhone = ph; }// Sets Phone

public void SetEmail(String email) { employeeEmail = email; }// Sets email

public void SetSalary(double salary) { employeeSalary = salary; }//Sets salary

// Returns employeeID

public int GetEmployeeID() { return(employeeID); }// getter for employeeID

// Returns employeeName

public String GetEmployeeName() { return(employeeName); }// getter for employeeName

// Returns employeeAddress

public String GetEmployeeAddress() { return(employeeAddress); }// getter for employeeAddress

// Returns employeePhone

public String GetEmployeePhone() { return(employeePhone); }// getter for employeePhone

// Returns employeeEmail

public String GetEmployeeEmail() { return(employeeEmail); }// getter for employeeEmail

// Returns employeeSalary

public double GetEmployeeSalary() { return(employeeSalary); }// getter for employeeSalary

// Returns a self-descriptive string

@Override

public String toString(){return "ID="+ employeeID + ", name=" + employeeName + ", address=" + employeeAddress + ", mobileNumber=" +

employeePhone + ", email=" + employeeEmail + ", salary=" + employeeSalary;}

}

//******** EmployeeAdmin.java *******************************

// The EmployeeAdmin class,subclass of Employee

class EmployeeAdmin extends Employee{

// private instance variable

private String position;

// constructs a employeeadmin instance with id,name,address,phone,email,salaray.position

public EmployeeAdmin( int id, String name, String addr, String ph, String email, double salary, String pos){

super(id,name,addr,ph,email,salary);

this.position = pos;}

// Getter and Setter

public void SetPosition( String pos) { this.position =pos; }// Sets position

public String GetPosition() { return(position); }// getter for position

// Returns a self-descriptive string

public String toString(){return super.toString() + "position=" +position;}}

//******** Doctor.java *******************************

// The Doctor class,subclass of Employee

class Doctor extends Employee{

// private instance variables

private String rank; //rank of the doctor

private String specialty;//the sprcialty of the doctor

// Constructs a Doctor instance with id,name,address,phone,email,salaray,rank,specialty

Doctor( int id, String name, String addr, String email, String ph, double salary,String rank, String spec){

super(id,name,addr,email,ph,salary);

this.rank = rank; this.specialty =spec;}

// Getters and Setters

public void SetRank( String rank) { this.rank = rank; }// Sets for rank

public void SetSpecialty(String spec) { this.specialty = spec; }// Sets for specialty

// Returns rank

public String GetRank() { return(rank); }// getter for rank

// Returns specialty

public String GetSpecialty() { return(specialty); }// getter for specialty

// Returns a self-descriptive string

public String toString(){return super.toString() + "rank=" + rank + ", specialty=" + specialty;}}

//******** Hospital.java *******************************

class Hospital {

List <Doctor> doctorList = new ArrayList<Doctor>();// Doctor list

List <EmployeeAdmin> EmployeeAdminList = new ArrayList<EmployeeAdmin>(); // EmployeeAdmin list

String hospitalName;

void addDoctor(Doctor o){doctorList.add(o);}

void addEmployeeAdmin(EmployeeAdmin o){EmployeeAdminList.add(o);}

Hospital(String name){this.hospitalName=name;}

public List<Doctor> showDoctors(){return doctorList;}// Return doctors list

public List<EmployeeAdmin> showEmployeeAdmin(){return EmployeeAdminList;}// Return EmplyeeAdmins list

}


Lavi M.

The code has few issues. Some issues are: 1- Don't make instatntiation of objects for every selection. 2- Make the Emplyee class as abstract. 3- Make the code clearer using indentations, spaces and comments.
Report

11/22/20

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.