Question
could you please provide the java code for this. I really need help please. The skeleton is provided in the bottom. The following tasks are
could you please provide the java code for this. I really need help please. The skeleton is provided in the bottom.
The following tasks are to done in the indicated classes:
Task #0 (in the SalariedEmployee class and the HourlyEmployee class)
Fix the error due to extending the Employee superclass
Note: the method for HourlyEmployee needs to get hours to compute weekly pay.
Create the toString() method
Task #1 - Define an arrayList, myEmployees, of Employee type (in the EmployeeDemo class)
Task #2: (in the EmployeeDemo class)
Add a try-catch block to handle FileNotFound & any general Exception
Add a finally clause, but check that the file was created before closing it
Task #3: (in the EmployeeDemo class)
Open the input file, stored in the project's directory
Use a try-catch-finally block to handle the fileNotFound condition
Within the try-catch block:
read the salaryEmp.txt file until the end of the file (firstName, lastName, annualSalary) for each record read, create a SalariedEmployee object, and put inside arrayList of myEmployees
read the hourlyEmp.txt file until the end of the file
for each record read, create an HourlyEmployee object, and put inside myEmployees arrayList (firstName, lastName, wage)
Task #4: (in the EmployeeDemo class)
Write a loop that, for each employee, will polymorphically display the employees data, ask the user for any missing data (hours), and then polymorphically calculate weeklyPay and display the pay.
package employeedemo;
public abstract class Employee { private String firstName; private String lastName; // private double hoursWorked; public Employee() { firstName = null; lastName = null; } public Employee(String aFirstName, String aLastName) { firstName = aFirstName; lastName = aLastName; // hoursWorked = anHoursWorked; } public void setFirstName(String aFirstName) { firstName = aFirstName; } public void setLastName(String aLastName) { lastName = aLastName; } /* public void setHoursWorked(double anHours) { hoursWorked = anHours; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } /* public double getHoursWorked() { return hoursWorked; } */ //Task 0: //Define .toString() public abstract double weeklyPay(int hours); }
public class EmployeeDemo {
//Define an arrayList of Employee type.
ArrayList
Scanner myKeyboard = new Scanner(System.in); int hoursWorked; EmployeeDemo myDemo = new EmployeeDemo(); myDemo.createEmployees(); myDemo.computeSalary(); } public void createEmployees() { // Please write code below, and place all objects inside of an arrayList String lastName, firstName; double salary
SalariedEmployee salEmp;
Scanner inFile = null; File myfile; boolean fileOpened = false; //read the file1 that contains only SalariedEmployees //create SalariedEmployees subclasses, and add them to the Employee arrayList //read the file2 that contains only HourlyEmployees //create HourlyEmployees subclass, and add them to the Employee arrayList } public void computeSalary() { // loop through the arrayList, and call the polymorphic method found in the superclass // and all of its subclasses. Print the results of the method's calculations Scanner keyboard = new Scanner(System.in); int hours; double pay; } }
package employeedemo;
public class HourlyEmployee extends Employee { private double wage; public HourlyEmployee(String firstName, String lastName, double wage) { super(firstName, lastName); this.wage = wage; } public void setWage(double aWage) { wage = aWage; } public double getWage() { return wage; } //Task 1: //Create the missing method, using the logic below: // double pay = wage * hoursWorked; // if (hoursWorked > 40) // { // int otHours = hoursWorked - 40; // double otPay = otHours * wage * .5; // pay = pay + otPay; // // } // return pay;
//Task 2: //Override .toString() by invoking the super class .toString and //then concatenating the HourlyEmployee -specific fields. }
package employeedemo;
public class Manager extends SalariedEmployee { private double weeklyBonus; public Manager(String aFirstName, String aLastName, double anAnnualSalary, double aWeeklyBonus) { super(aFirstName, aLastName, anAnnualSalary); weeklyBonus = aWeeklyBonus; } public void setWeeklyBonus(double aBonus) { weeklyBonus = aBonus; } public double getWeeklyBonus() { return weeklyBonus; } //Define the missing method using the logic below: // double pay = super.weeklyPay(hours) + weeklyBonus; // return pay; //Override .toString() to invoke the superclass .toString() and concatenate all the remaining fields }
package employeedemo;
public class SalariedEmployee extends Employee{ private double annualSalary; public SalariedEmployee(String aFirstName, String aLastName, double anAnnualSalary) { super(aFirstName, aLastName); annualSalary = anAnnualSalary; } public void setAnnualSalary(double anAnnualSalary) { annualSalary = anAnnualSalary; } public double getAnnualSalary() { return annualSalary; } //Define the missing method using the logic below: // // final int WEEKS_PER_YEAR = 52; // double pay = annualSalary/ WEEKS_PER_YEAR; // return pay; //Override the .toString() method, by invoking the superclass .toString() and //concatenating the remaining fields in this subclass }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started