employees.txt Need this in java and according to the assignment, thanks! This fi
ID: 3740981 • Letter: E
Question
employees.txt
Need this in java and according to the assignment, thanks!
This fifth assignment will allow you to explore the important O0 concept of Inheritance in a Java implementation. This assignment will also give you time to explore this important pillar (and maybe all four..) of the O0 paradigm and allow you to ramp up to the exciting, fun, yet very challenging sixth assignment. For this assignment, you are tasked with the responsibility of building the framework for the Healthy Pharmacy that we discussed in lab/recitation. The Healthy Pharmacy is looking to develop a software application to model their employee hierarchy. Currently the pharmacy has the following types of job titles for their employees: Staff Pharmacist, Pharmacy Manager, Staff Technician, and Senior Technician. Healthy Pharmacy has elected to proceed with an hourly payment schedule for all employees- obviously the rates for each job title, degrees, and skills will vary (e , a Pharmacy Manager will make more per hour than a Technician). Every employee will have the following attributes: Employee ID (Integer) First Name (String) Last Name (String) Hourly Rate (Double) A Pharmacy Manager will have the following attributes: . Leadership (Boolean) A Staff Pharmacist will have the following attributes: .Licensed (Boolean) A Senior Technician will have the following attributes .Service Award (Boolean) A Staff Technician will have the following attributes . Degree (Boolean) This program wil be written in Java and must compile and run on Tesla (tesla.cs.iupui.edu). Your program will be menu driven in which you will provide the following prompts to the user 1. 2. Load Employees (From File) Exit Program Once the user has loaded the employees the following options should be provided 1 Print Employee Information 2. Enter Hours Worked 3. Calculate Paychecks 4. Exit ProgramExplanation / Answer
code:
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
class Employee {
protected int Employee_ID;
protected String Emp_firstName;
protected String Emp_lastName;
protected int Emp_hourlyRate;
public Employee(int Employee_ID, String Emp_firstName, String Emp_lastName, int Emp_hourlyRate) {
this.Employee_ID = Employee_ID;
this.Emp_firstName = Emp_firstName;
this.Emp_lastName = Emp_lastName;
this.Emp_hourlyRate = Emp_hourlyRate;
}
public int getEmpID() {
return Employee_ID;
}
public void setEmpID(int Employee_ID) {
this.Employee_ID = Employee_ID;
}
public String getEmpFirstName() {
return Emp_firstName;
}
public void setEmpFirstName(String Emp_firstName) {
this.Emp_firstName = Emp_firstName;
}
public String getEmpLastName() {
return Emp_lastName;
}
// to set employee last Name
public void setEmpLastName(String Emp_lastName) {
this.Emp_lastName = Emp_lastName;
}
// to get employee hourly rate
public double getHrlyRate() {
return Emp_hourlyRate;
}
// to set employee hourly rate
public void setHrlyRate(int Emp_hourlyRate) {
this.Emp_hourlyRate = Emp_hourlyRate;
}
// to calculate employee pay
public double calculatePay(int hours) {
return Emp_hourlyRate*hours;
}
// to print the info
@Override
public String toString() {
return String.format("ID: %-20dName: %-20sRate: %- 20d",Employee_ID,Emp_firstName+" "+Emp_lastName,Emp_hourlyRate);
}
}
// derived class PharmacyManager
class PharmacyManager extends Employee {
// local variables
int Prmcy_jobID;
String stDate;
static final int Emp_hourlyRate=50;
// constructor to the class
public PharmacyManager(int Employee_ID, String Emp_firstName, String Emp_lastName, int Prmcy_jobID, String stDate) {
super(Employee_ID, Emp_firstName, Emp_lastName, Emp_hourlyRate);
this.Prmcy_jobID = Prmcy_jobID;
this.stDate = stDate;
}
}
// derived class Pharmacist
class Pharmacist extends Employee {
// local variables
int Pr_jobID;
String stDate;
static final int Emp_hourlyRate=40;
// constructor to the class
public Pharmacist(int Employee_ID, String Emp_firstName, String Emp_lastName, int Pr_jobID, String stDate) {
super(Employee_ID, Emp_firstName, Emp_lastName, Emp_hourlyRate);
this.Pr_jobID = Pr_jobID;
this.stDate = stDate;
}
// to get job id
public int getprmJobID() {
return Pr_jobID;
}
// to set job id
public String getStDate() {
return stDate;
}
}
// derived class Technician
class Technician extends Employee {
// local variables
int Tech_jobID;
String stDate;
static final int Emp_hourlyRate=20;
// constructor to the class
public Technician(int Employee_ID, String Emp_firstName, String Emp_lastName, int Tech_jobID, String stDate) {
super(Employee_ID, Emp_firstName, Emp_lastName, Emp_hourlyRate);
this.Tech_jobID = Tech_jobID;
this.stDate = stDate;
}
// to get job id
public int tecJobID() {
return Tech_jobID;
}
// to set job id
public String getStDate() {
return stDate;
}
}
// derived class SeniorTechnician
class SeniorTechnician extends Employee {
// local variables
int STech_jobID;
String stDate;
static final int Emp_hourlyRate=25;
public SeniorTechnician(int Employee_ID, String Emp_firstName, String Emp_lastName, int STech_jobID, String stDate) {
super(Employee_ID, Emp_firstName, Emp_lastName, Emp_hourlyRate);
this.STech_jobID = STech_jobID;
this.stDate = stDate;
}
// to get job id
public int getStecJobID() {
return STech_jobID;
}
// to set job id
public String getStDate() {
return stDate;
}
}
// Driver class to test the code
public class Driver {
static Employee[] DrvrEmply = new Employee[4];
static int cnt;
static int drvrworkHours;
// menu function1
public static void mnMenu() {
System.out.println("1.Load Employees (From File)");
System.out.println("2.Exit Program");
}
// menu function2
public static void empMenu() {
System.out.println();
System.out.println("1.Print Employee Information");
System.out.println("2.Enter Hours Worked");
System.out.println("3.Calculate Paychecks");
System.out.println("4.Exit Program");
}
// main menu
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int menu1Opt;
int menu2Opt;
mnMenu();
System.out.print("Enter your selection:");
menu1Opt = scnr.nextInt();
if (menu1Opt == 1) {
loadEmployee("employees.txt");
} else {
System.exit(1);
}
while (true) {
empMenu();
System.out.print("Enter your selection:");
menu2Opt = scnr.nextInt();
switch (menu2Opt) {
case 1:
display();
break;
case 2:
System.out.print(" Please enter the hours worked: ");
drvrworkHours = scnr.nextInt();
break;
case 3:
if (drvrworkHours == 0) {
System.out.println("Please enter the hours worked(option #2) before trying to calculate paycheck amount");
} else {
calculatePay();
}
break;
case 4:
System.out.println("Good Bye !");
System.exit(0);
}
}
}
// function to load the data from file to array and process it
public static void loadEmployee(String fileName) {
try (Scanner scnr = new Scanner(new FileReader(fileName))) {
while (scnr.hasNext()) {
String[] data = scnr.nextLine().split(",");
int drvjobId = Integer.parseInt(data[0]);
int drvempId = Integer.parseInt(data[1]);
String Emp_firstName = data[2];
String Emp_lastName = data[3];
String stDate = data[4];
switch (drvjobId) {
case 1:
DrvrEmply[cnt++] = new PharmacyManager(drvempId, Emp_firstName, Emp_lastName, drvjobId, stDate);
break;
case 2:
DrvrEmply[cnt++] = new Pharmacist(drvempId, Emp_firstName, Emp_lastName, drvjobId, stDate);
break;
case 3:
DrvrEmply[cnt++] = new Technician(drvempId, Emp_firstName, Emp_lastName, drvjobId, stDate);
break;
case 4:
DrvrEmply[cnt++] = new SeniorTechnician(drvempId, Emp_firstName, Emp_lastName, drvjobId, stDate);
break;
}
}
System.out.println(" File Successfully Loaded!");
} catch (FileNotFoundException excep) {
System.out.println("File Load Failed!");
System.out.println(excep.getClass() + " : " + excep.getMessage());
System.out.println("Program Exiting....");
System.exit(1);
}
}
// function to display the content
public static void display() {
System.out.println();
for (int lp = 0; lp< cnt; lp++) {
System.out.println(DrvrEmply[lp]);
}
}
// function to calculate the pay
public static void calculatePay() {
System.out.println();
for (int lp = 0; lp< cnt; lp++) {
System.out.println(String.format("ID: %-15dCheck Amount: $%-15.2f", DrvrEmply[lp].getEmpID(), DrvrEmply[lp].calculatePay(drvrworkHours)));
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.