Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions: (This is the same asmt we did in class, the only difference is that the data file does not tell us how many employees

Instructions: (This is the same asmt we did in class, the only difference is that the data file does not tell us how many employees we have. You need to figure out how to handle this situation.) ----------------- Write a program to model three different kinds of employees in a company using inheritance and File I/O. Your program will consist of three classes that extend the class Employee and a testing class Payroll.java that reads in payroll information from a file then prints it to the console window. The Classes Manager, HourlyWorker, and CommissionEmployee: ----------------------------------------------------------------------------------------- To model different types of employees, extend the provided abstract class Employee by writing three new classes: Manager, HourlyWorker, and CommissionEmployee. Implement the abstract methods as required. Managers get paid a fixed weekly salary, commission employees get paid based on base salary and commission (commission rate x sales), hourly workers get paid an hourly wage with time-and-a-half: 1.5 times the hourly wage for hours worked over 40 hours. Do not create additional fields, and only write methods that override methods from either Employee or Object. The Class Payroll: Create a class called Payroll with a main method to test your classes. This method should create an array of type Employee (think about what size you use?) Then, populate the array using data from the text file payroll.txt using appropriate Java I/O techniques. Each line of the file will look similar to one of these: #Steve, Davis,2000 *John, Kanet, 800, 7000, 0.10 @Thomas, Hill, 20, 50 *Lisa, Green,800,6000,0.10 In order to populate the array, you will need to split() each String on the (,) character so you can access each individual value of data. Based on the first value (e.g., #) your method will know whether to create a new Manager, HourlyWorker, or CommissionWorker object. Once created, populate the object with the remaining values then store it in the array. Finally, iterate through the array of employees using the enhanced for loop syntax, and print out each employee in the following format: Manager: Steve Davis $2000 Commission Employee: John Kanet $1500 (Base salary: $800, sales: $7000, Commission rate: 10%) Hourly Worker: Thomas Hill $1100 (Hourly wage: $20, hours worked: 50) 

given

Employee.java

public abstract class Employee {

private String firstName; private String lastName; private static int employeeID=100;

public Employee(String firstName, String lastName) { setFirstName(firstName); setLastName(lastName); employeeID++; } public void setFirstName(String firstName){ this.firstName=firstName; } public String getFirstName(){ return firstName; } public void setLastName(String lastName){ this.lastName=lastName; } public String getLastName(){ return lastName; }

public int getEmplyeeID(){ return employeeID; } public String toString(){ return String.format("%20s%20s", firstName, lastName); } public abstract double earnings(); }

payroll2.txt

#Steve, Davis, 2000 *John, Kanet, 800, 7000, 0.10 @Thomas, Hill,20,50 *Lisa, Green,800,6000,0.10 *Chasidy , Funderburk,1000,5000,0.08 @Kayleigh , Bertrand, 25, 45 *Zane, Eckhoff,1800,900, 0.09 @Teressa, Bitterman, 15,35 *Yuri, Viera, 600, 5000,0.10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Jay Greenspan, Brad Bulger

1st Edition

ISBN: 978-0764535376

More Books

Students also viewed these Databases questions

Question

What are the five components of total rewards?

Answered: 1 week ago