Lavi M.
asked 11/22/20Can 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
}
1 Expert Answer
I do not see a single file being written to or read from. When the program terminates, ALL of the data that was input is GONE and LOST forever. You then must INPUT all of the data again, and AGAIn, AND AGAIN!!!!
Your project, at minimum, requires SIX (6) FILES:
(1) Doctors
(2) Patients
(3) EmployeeAdmins
(4) Services
(5) Doctor/Patient association : cross table
(6) Patient/Treatment association : cross table
For each table, you must provide the following methods:
(1) Adds a record to the array (WHICH REQUIRES Instantiation)
(2) Writes the array to file (which requires instantiation of FILE objects)
(3) Reads the array from file (which required instantiation of FILE objects)
(4) Updates the array (which requires the instantiation of a temporary object)
(5) Linear searches the array (which requires instantiation of a target object)
(6) Indexes the array and returns the object at a specified index (ALWAYS RETURNS
a COPY!!! NEVER return the original)
That is 36 methods that need implementing !!!
So as you can see, your request is UNREASONABLE. All of these actions require the instantiation of at least one object. That statement does not make any sense. The sole purpose of Java is to instantiate objects, so that they can co-operate and complete a task.
This is the FIRST time I have heard that the Employee class must be ABSTRACT. The original project , I was told that the Employee MUST contain an id #, name, address , etc. while the Doctor and Admin classes inherit those, and add RANK, SPECIALTY, and Job description/position...
The problem is YOU CANNOT HAVE MEMBER vars in abstract classes. They will be declared STATIC and FINAL since the class is abstract. THerefore you will not be able to change them, which is unacceptable.
So again, that statement doesn't make any sense.
Documenting and cleaning up the code is the responsibility of you and your co-workers.
Indent 3 spaces every block... put a comment block at the top of each function, which describes
the following: (1) input parameters: what gets passed to the function (2) output values and return values: what results are produced and what gets returned (3) any global or external objects that get changed, any member vars that get changed, and what gets written to the database; basically anything or anyone that is affected (4) exceptions that are thrown if any and what causes them (5) any design issues (6) KNOWN bugs or glitches that remain unsolved
from there you document ONE COMMENT per block. so you code ends up looking like this:
/**********************************************
Method: name
input parameters:
output parameters:
side effects:
design issues:
bugs:
exceptions:
**************************************************/
ClassName_Method( params)
{
local vars;
//start block
{
//nested block
{
}
}
}
I have the DOCTOR portion of the code working. It is able to add a new doctor to the list and displays the arrays of doctors from the menu. I also have the PATIENT portion of the database done, but it needs tested and the functionality needs implemented in the menu system.
If you see what I am doing with the DOCTOR methods, the rest of it is EASY to understand and can be
finished by copy and paste, and then changing the array and counter variable names. The menu logic
is also the same. The only part that is a little tricky is that every patient MUST be assigned a doctor and
SERVICE performed must be assigned to a patient, which is the addition of two records in the cross-tables.
Yes, using a REAL database is also an option, which is yet another question to I have yet to receive a VALID response as of this writing. You all have been working on the project for awhile now and the database design, and requirements overall are UNCLEAR, every changing, undefined, sloppy and incomplete. I want the ORIGINAL paper of the assignment from your teacher, so I can see what is REALLY needed.
That leaves about 30-35 methods that need implemented, which I am leaving for YOU.
Send me an email and you will see how easy it is, which can be completed by copying and pasting. You can click on the icon to get my email link, which is patrick dot baldwin dot 1 at wyzant dotcom.
I await your email
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
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.11/22/20