Question: USING JAVA: PART 1: Go back to Chapter 6 and write a Payroll class as per the the directions. https://www.chegg.com/homework-help/starting-out-with-java-6th-edition-chapter-6-problem-5PC-solution-9780133957068 Code for part 1 is
USING JAVA:
PART 1:
Go back to Chapter 6 and write a Payroll class as per the the directions.
https://www.chegg.com/homework-help/starting-out-with-java-6th-edition-chapter-6-problem-5PC-solution-9780133957068
Code for part 1 is done here:
Payroll.java
class payroll { private String Name; private int ID; private int hourly_rate; private int hours; public payroll() { Name=" "; ID=0; hourly_rate=0; hours=0; } public payroll(String name, int id) { Name=name; ID=id; } public void setName(String name) { Name=name; } public void setID(int id) { ID=id; } public void setHourlyRate(int rate) { hourly_rate=rate; } public void setHours(int hrs) { hours=hrs; } public String getName() { return Name; } public int getId() { return ID; } public int getHourlyRate() { return hourly_rate; } public int getHours() { return hours; } public int grossPay() { return (hourly_rate*hours); } }
PayrollTest.java
import java.util.Scanner;
class PayrollTest { public static void main(String [] args) { String name, s1; int hrs, rate, id; payroll employee=new payroll(); Scanner keyboard = new Scanner(System.in); System.out.println("Enter name: "); name = keyboard.nextLine(); System.out.println("Enter Id: "); s1=keyboard.nextLine(); id=Integer.parseInt(s1); System.out.println("Enter hourly rate: "); s1=keyboard.nextLine(); rate=Integer.parseInt(s1); System.out.println("Enter hours rate: "); s1=keyboard.nextLine(); hrs=Integer.parseInt(s1); employee.setName(name); employee.setID(id); employee.setHourlyRate(rate); employee.setHours(hrs); System.out.println("Name: "+employee.getName()); System.out.println("ID: "+employee.getId()); System.out.println("Hourly rate: "+employee.getHourlyRate()); System.out.println("Gross: "+employee.grossPay()); System.exit(0); keyboard.close(); } }
PART 2:
In addition to computing the gross pay above, add fields for federal and state income tax rates, and compute pay after taxes. You may use 12% and 4% respectively for these tax rates.
PART 3:
After completing the above, complete Chapter 11 #5 by writing the requested exceptions. Write a separate Demo Class to show that your Payroll class works and that when erroneous data is provided, the appropriate exceptions are thrown.
Write exception classes for the following error conditions:
An empty string is given for the employees name.
An invalid value is given for the employees ID number. If you implemented this field as a string, then an empty string would be invalid. If you implemented this field as a numeric variable, then a negative number or zero would be invalid.
An invalid number is given for the number of hours worked. This would be a negative number or a number greater than 84.
An invalid number is given for the hourly pay rate. This would be a negative number or a number greater than 25.
Modify the Payroll class so that it throws the appropriate exception when any of these errors occurs. Demonstrate the exception classes in a program.
So I finished part 1, I just need help with parts 2 & 3. PLEASE Use Java and make sure everything compiles. If classes need to be in a separate file, please let me know! THANK YOU!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
