Question
Design a Payroll class that has fields for an employees name, ID number, hourly pay rate, and number of hours worked. I believe that I
Design a Payroll class that has fields for an employees name, ID number, hourly pay rate, and number of hours worked.
I believe that I already posted this question but, I am having trouble with a particular part of it. This Is the part I have not learned on my own must include in my code:
*******Make sure that the class is serializable******. Write a method to serialize the object to a file. File name should be passed as a parameter. Write a method that deserializes the object from the file.(this here is what i am asking for help with) I am aware that the code I have given you is not complete mayble one or two lines off (more of demo code) but it should be enough to help with serializing the code.
private String name; private int id; private double rate; private double hoursWorked; public Payroll(String name, int id ) throws InvalidNameException,InvalidIDException { setName(name); setId(id); } public String getName() { return name; } public void setName(String empName) throws InvalidNameException { if(empName == null || empName.equals("")){ throw new InvalidNameException("Invalid Name. Name can not be empty"); } this.name = empName; } public int getId() { return id; } public void setId(int empID) throws InvalidIDException { if(empID <= 0){ throw new InvalidIDException("EmpID can not be negative or zero"); } this.id = empID; } public double getHourlyRate() { return rate; } public void setHourlyRate(double rate)throws HourlyRateException { if(rate < 0 || rate > 25 ){ throw new HourlyRateException("rate can not be negative or greater than 25"); } this.rate = rate; } public double getHoursWorked() { return hoursWorked; } public void setHoursWorked(double hours) throws ValidHoursException { if(hours < 0 || hours > 84 ){ throw new ValidHoursException("hours c
public static void main(String[] args) throws HourlyRateException,InvalidIDException,ValidHoursException,InvalidNameException { Scanner in = new Scanner(System.in); String name; int empID; System.out.print("Enter employee's name: "); name = in.next(); System.out.print("Enter employee's empID: "); empID = in.nextInt(); Payroll payroll = new Payroll(name, empID); System.out.print("Enter employee's hourly rate: "); double rate = in.nextDouble(); payroll.setHourlyRate(rate); System.out.print("Enter employee's number of hours worked: "); double hours = in.nextDouble(); payroll.setHoursWorked(hours); //Payroll.main(name, empID, rate, hours);
System.out.println("Gross pay is " + payroll.getGrossPay()); }
}
here are a few snippets o
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