Question
Assignment # 5: Written in a Java code for this assignment how do I do the next part of adding the Taxpayment Class?: We are
Assignment # 5: Written in a Java code for this assignment how do I do the next part of adding the Taxpayment Class?: We are going to add the following to our class set. 1. Create a new class called TaxPayment which has the following fields: a. FederalTax b. StateTax c. FicaTax 2. Add an instance of this class to the pay period class so we have a place to store it 3. Create a new class called TaxManager that has the following methods: a. TaxPayment ComputeTaxPayment(double grossPay, TaxRates taxRates) This should return the taxes for this employee, which can then be stored in the payperiod class b. We are making TaxManager a separate class so eventually we have a place to put different tax rates 4. Use the following default rates for tax rates a. FederalRate 15% b. StateRate 5% c. FicaRate 3% 5. You should use TaxManager in your printPaystub method to calculate and display the appropriate taxes.
This is the code put down so far:
import java.util.Date; import java.util.Scanner; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.concurrent.TimeUnit; public class Assignment5 { public static void main(String[] args) { Employee emp = new Employee(); int employeeId; String firstName, lastName, middleInitial; String address; int zipCode; long phoneNumber; String emailId; double hourlyRate; Scanner sc = new Scanner(System.in); System.out.print("Enter the Employee ID: "); employeeId = sc.nextInt(); System.out.print("Enter the First Name: "); firstName = sc.next(); System.out.print("Enter the Last Name: "); lastName = sc.next(); System.out.print("Enter the Middle Initial: "); middleInitial = sc.next(); System.out.print("Enter the address: "); address = sc.next(); System.out.print("Enter the Zip Code: "); zipCode = sc.nextInt(); System.out.print("Enter the Phone Number: "); phoneNumber = sc.nextLong(); System.out.print("Enter the Email ID: "); emailId = sc.next(); System.out.print("Enter the Hourly Rate: "); hourlyRate = sc.nextDouble(); emp.setData(employeeId, firstName, lastName, middleInitial, address, zipCode, phoneNumber, emailId, hourlyRate); int payPeriodID; String startDate = "10-28-2020 01:10:20", endDate = "10-29-2020 01:10:20"; int noOfHours, hoursADay; System.out.print("Enter the PayPeriod ID: "); payPeriodID = sc.nextInt(); System.out.println("Enter the total number of hours and hours worked in a day: "); noOfHours = sc.nextInt(); hoursADay = sc.nextInt(); PayPeriod pr = new PayPeriod(); pr.setData(payPeriodID, employeeId, startDate, endDate, noOfHours, hoursADay); PayrollManager.printPayStub(emp, pr); } } class Employee { // Member variables private int employeeId; private String firstName, lastName, middleInitial; private String address; private int zipCode; private long phoneNumber; private String emailId; private double hourlyRate; // Setter function public void setData(int employeeId, String firstName, String lastName, String middleInitial, String address, int zipCode, long phoneNumber, String emailId, double hourlyRate) { this.employeeId = employeeId; this.firstName = firstName; this.lastName = lastName; this.middleInitial = middleInitial; this.address = address; this.zipCode = zipCode; this.phoneNumber = phoneNumber; this.emailId = emailId; this.hourlyRate = hourlyRate; } public void getData() { System.out.println("Name is: " + firstName + " " + middleInitial + " " + lastName); System.out.println("Employee ID is: " + employeeId); System.out.println("Address is: " + address + " " + zipCode); System.out.println("Contact Info: " + "Phone: " + phoneNumber + " Email: " + emailId); System.out.println("Hourly Rate: " + hourlyRate); } public double getHourlyRate() { return hourlyRate; } } class PayPeriod { private int payPeriodId; private int employeeId; private String startDate, endDate; private int totalNoOfHours; private int totalHoursInADay; public void setData(int payPeriodId, int employeeId, String startDate, String endDate, int totalNoOfHours, int totalHoursInADay) { this.payPeriodId = payPeriodId; this.employeeId = employeeId; this.startDate = startDate; this.endDate = endDate; this.totalNoOfHours = totalNoOfHours; this.totalHoursInADay = totalHoursInADay; } // Calculate difference between start date and end date public long getTotalDurationInDays() { SimpleDateFormat sdf = new SimpleDateFormat( "dd-MM-yyyy HH:mm:ss"); long difference_In_Time, difference_In_Days = 0; try { // parse method is used to parse // the text from a string to // produce the date Date d1 = sdf.parse(startDate); Date d2 = sdf.parse(endDate); difference_In_Time = d2.getTime() - d1.getTime(); difference_In_Days = TimeUnit .MILLISECONDS .toDays(difference_In_Time) % 365; } catch (ParseException e) { e.printStackTrace(); } return difference_In_Days; } public int getTotalNoOfHours() { return totalNoOfHours; } public int getTotalHoursInADay() { return totalHoursInADay; } } class PayrollManager { // To calculate regular pay: hourly rate * total hours worked in the duration public static double calculateRegularPay(Employee emp, PayPeriod pr) { System.out.println("Days Worked: " + pr.getTotalDurationInDays()); return emp.getHourlyRate() * (pr.getTotalDurationInDays() * pr.getTotalHoursInADay()); } // If extra hours worked then calculate remaining extra hours from the regular hours public static double calculateOvertimePay(Employee emp, PayPeriod pr) { double overtimePay = 0; if(pr.getTotalNoOfHours() > pr.getTotalDurationInDays() * pr.getTotalHoursInADay()) { overtimePay = emp.getHourlyRate() * (pr.getTotalNoOfHours() - (pr.getTotalDurationInDays() * pr.getTotalHoursInADay())); } return overtimePay; } // Overtime pay + Regular pay = Gross Pay public static double calculateGrossPay(Employee emp, PayPeriod pr) { return calculateOvertimePay(emp, pr) + calculateRegularPay(emp, pr); } public static void printPayStub(Employee emp, PayPeriod pr) { emp.getData(); System.out.println("Regular Pay: " + calculateRegularPay(emp, pr) + " " + "Overtime Pay: " + calculateOvertimePay(emp, pr) + " " + "Gross Pay: " + calculateGrossPay(emp, pr)); } }
What will the code look like with the Tax Payment Class added?
Assignment #5: Calculate Taxes In this assignment we are going to add logic to calculate taxes Input Expected: Same as Assignment #2 Sample Run: Inputs: Enter Employee Id: 123456 Enter Employee first name: Larry Enter Employee last name: Schoeneman Enter # of hours worked this week: 50 Enter hourly rate of pay: $10.00 Output: Employee Id : 123456 Last Name: Schoeneman First Name: Larry Week of 6/11/2020 (use current date) Hours Worked: 50 Hourly Rate: $10.00 Regular Pay: 40 hours at $10/hr: $400.00 Overtime Pay: 10 hours at $15/hr: 150 Gross Total: $650.00 Federal Tax: $65.00 State Tax: $35.00 FICA: $20.00 Net Pay: $530.00 Specification: We are going to add the following to our class set. a. 1. Create a new class called TaxPayment which has the following fields: FederalTax b. State Tax c. Fica Tax 2. Add an instance of this class to the pay period class 50 have a place to store it 3. Create a new class called TaxManager that has the following methods: a. TaxPayment ComputeTaxPayment(double grossPay, TaxRates taxRates) - This should return the taxes for this employee, which can then be stored in the payperiod class b. We are making TaxManager a separate class so eventually we have a place to put different tax rates 4. Use the following default rates for tax rates a. Federal Rate -15% b. State Rate -5% c. FicaRate-3 5. You should use Tax Manager in your printPaystub method to calculate and display the appropriate taxes. Example Input Enter Employee first name:Larry Enter Employee last name:Schoeneman Enter middle initial:X Enter address:1219 Rose Court East Enter city:Buffalo Grove Enter state:IL Enter zipcode:60089 Enter email:lschoeneman@harper.edu Enter phone:121-124-1234 Enter hourly rate of pay:10 Enter hours worked:40 Example Output Employee Id : 1 Last Name: Schoeneman First Name: Larry Middle Initial: X Address: 1219 Rose Court East, Buffalo Grove, IL 60089 Phone: 121-124-1234 Email:Ischoeneman@harper.edu Hours Worked: 40.0 Hourly Rate: $10.0 Gross Total: $400.0 Taxes: Federal Tax:$60.0 State Tax:$20.0 Fica Tax:$12.0 Net Paycheck: $308.0
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