In: Computer Science
You are to modify your payroll program from the last assignment to take the new copy of the payroll file called DeweyCheatemAndHow.txt which has the fields separated by a comma to use as input to your program and produce a file that lists all the salaried employee and their gross pay, then each hourly employee and their gross pay and finally each piece rate employee and their gross pay .
You are to process all the entries provided in the file and produce output that looks like this:
Dewey, Cheatem and How Law Firm
Payroll Repor
t Salaried Employees
First Name Last Name SSN Gross Pay $XXX.
First Name Last Name SSN Gross Pay $XXX.
First Name Last Name SSN Gross Pay $XXX.
Hourly Employees
First Name Last Name SSN Gross Pay $XXX.
First Name Last Name SSN Gross Pay $XXX.
Piece Rate Employees
First Name Last Name SSN Gross Pay $XXX.
First Name Last Name SSN Gross Pay $XXX.
In order to be able to group the employee types for the output you will need to use an array of employee and its size should be 30. Please note there will not be 30 entries in the DeweyCheatemAndHow.txt.
The input file has this :
s,028-13-3948,Andrew,Smith,1313,Mockingbird,Lane,513-556-7000,500.75s,028-24-9971,Andrew,Whaley,1776,Liberty,Ave,513-556-7001,675h,112-45-7867,Saif,Altarouti,3427,Smith,Rd,513-556-7002,20,40s,123-45-6789,Nicholas,Alonso,920,Ohio,Ave,513-556-7003,900s,123-94-3938,Abigail,Smith,1600,Penn,St,513-556-7004,1200h,123-97-4556,Matthew,Stewart,2925,Campus,Green,513-556-7005,16.5,40s,142-78-2367,Syeda,Mullen,345,Ludlow,Ave,513-556-7006,763p,143-49-0923,Arianna,Rhine,768,Stratford,Dr,513-556-7007,7.5,1000p,193-93-1283,Emmalese,Nuerge,132,Greyfox,Rd,513-556-7008,8.5,1010p,211-54-823,Joshua,Ayers,671,Buckwheat,Rd,513-556-7009,5.5,500h,258-29-9102,Nicholas,Roth,734,Student,Dr,513-556-7010,25,35
Language is Java
Here i am giving the answer. Hope it helps. please upvote. it helps me a lot.
//Employee class
public class Employee {
private String Firstname;
private String Lastname;
private String Address;
private String Phone;
private String SSN;
//CONSTRUCTORS
public Employee() {
// TODO Auto-generated constructor stub
}
public Employee(String firstname, String lastname, String address,
String phone, String sSN) {
super();
Firstname = firstname;
Lastname = lastname;
Address = address;
Phone = phone;
SSN = sSN;
}
//SETTERS FOR FIRSTNAME, LASTNAME, SSN
public void setFirstname(String firstname) {
Firstname = firstname;
}
public void setLastname(String lastname) {
Lastname = lastname;
}
public void setSSN(String sSN) {
SSN = sSN;
}
//GETTERS FOR FIRSTNAME, LASTNAME, SSN, ADDRESS, PHONE
public String getFirstname() {
return Firstname;
}
public String getLastname() {
return Lastname;
}
public String getAddress() {
return Address;
}
public String getPhone() {
return Phone;
}
public String getSSN() {
return SSN;
}
//TOSTRING METHOD
@Override
public String toString() {
return "Employee [Firstname=" + Firstname + ",
Lastname=" + Lastname + ", Address=" + Address + ", Phone=" + Phone
+ ", SSN=" + SSN + "]";
}
//EQUALS METHOD
@Override
public boolean equals(Object obj) {
if (this == obj)
return
true;
if (obj == null)
return
false;
if (getClass() !=
obj.getClass())
return
false;
Employee other = (Employee)
obj;
if (Address == null) {
if
(other.Address != null)
return false;
} else if
(!Address.equals(other.Address))
return
false;
if (Firstname == null) {
if
(other.Firstname != null)
return false;
} else if
(!Firstname.equals(other.Firstname))
return
false;
if (Lastname == null) {
if
(other.Lastname != null)
return false;
} else if
(!Lastname.equals(other.Lastname))
return
false;
if (Phone == null) {
if (other.Phone
!= null)
return false;
} else if
(!Phone.equals(other.Phone))
return
false;
if (SSN == null) {
if (other.SSN !=
null)
return false;
} else if
(!SSN.equals(other.SSN))
return
false;
return true;
}
}
//SALARIED CLASS
public class Salaried extends Employee {
private double Salary;
//CONSTRUCTORS
public Salaried() {
// TODO Auto-generated constructor stub
}
public Salaried( double salary ) {
super();
Salary = salary;
}
//SET METHOD FOR SALARY
public void setSalary(double salary) {
Salary = salary;
}
//GET METHOD FOR SALARY
public double getSalary() {
return Salary;
}
//TOSTRING METHOD
@Override
public String toString() {
return "Salary=" + Salary ;
}
}
//HOURLY CLASS
public class Hourly extends Employee {
private double PayRate;
private double HoursWorked;
//CONSTRUCTORS
public Hourly() {
// TODO Auto-generated constructor stub
}
public Hourly(double payRate, double hoursWorked) {
super();
PayRate = payRate;
HoursWorked = hoursWorked;
}
//SETTERS FOR Payrate, HoursWorked
public void setPayRate(double payRate) {
PayRate = payRate;
}
public void setHoursWorked(double hoursWorked) {
HoursWorked = hoursWorked;
}
//GETTERS FOR hoursWorked, Payrate
public double getPayRate() {
return PayRate;
}
public double getHoursWorked() {
return HoursWorked;
}
//TOSTRING METHOD
@Override
public String toString() {
return "Hourly [PayRate=" + PayRate + ", HoursWorked="
+HoursWorked + "]";
}
double pay(){
return PayRate * HoursWorked;
}
}
//PIECE CLASS
public class Piece extends Employee {
private int Quantity;
private double PieceRate;
//CONSTRUCTORS
public Piece() {
// TODO Auto-generated constructor stub
}
public Piece(int quantity, double pieceRate) {
super();
Quantity = quantity;
PieceRate =pieceRate ;
}
//SETTERS FOR Quantity, pieceRate
public void setQuantity(int quantity) {
Quantity = quantity;
}
public void setPieceRate(double pieceRate) {
PieceRate = pieceRate;
}
//GETTERS FOR PieceRate, Quantity
public int getQuantity() {
return Quantity;
}
public double getPieceRate() {
return PieceRate;
}
//TOSTRING METHOD
@Override
public String toString() {
return "Piece [Quantity=" + Quantity + ", PieceRate="
+PieceRate + "]";
}
double pay(){
return Quantity * PieceRate;
}
}
//main function
public static void main(String[] args){
Employee employee[]= new Employee[20];
try{
File file=new File("https://easyupload.io/mpkorw");
BufferedReader br=new BufferedReader(new FileReader(file));
int r=0;
while((r=br.read())!=-1)
{
//Code ssn first name last name address phone salary
//s 123-45-6789 William Tell 1313 Mockingbird lane 513-556-7058 500.75
Salaried s=new Employee();
Hourly h= new Employee();
Piece p=new Employee();
//group the employee types for the output
//keep them in the array of employee
}
}
catch(Exception e)
{
//file not found
e.printStackTrace();
}
System.out.println("Dewey, Cheatem and How Law Firm");
System.out.println("Payroll Report");
System.out.println("Salaried Employees");
for(int i=0;i<employee.length; i++)
System.out.println("First Name : " +s.Firstname +" Last Name: " +s.Lastname+ "SSN : "+s.SSN + " Gross Pay:" + s.pay());
System.out.println("Hourly Employees");
for(int i=0;i<employee.length; i++)
System.out.println("First Name : " +h.Firstname +" Last Name: " +h.Lastname+ "SSN : "+h.SSN + " Gross Pay:" + h.pay());
System.out.println("Piecerate Employees");
for(int i=0;i<employee.length; i++)
System.out.println("First Name : " +p.Firstname +" Last Name: " +p.Lastname+ "SSN : "+p.SSN + " Gross Pay:" + p.pay());
}
Thank you. please upvote.