Lab4 go brrrrrr 2!

master
Chloe Fontenot 🏳️‍⚧️ 2022-08-31 09:24:50 +07:00
parent 7bf6031fd4
commit 3099ec56e4
4 changed files with 28 additions and 10 deletions

@ -4,6 +4,7 @@
*/ */
package com.calebfontenot.lab4_calebfontenot; package com.calebfontenot.lab4_calebfontenot;
import java.text.DecimalFormat;
import java.util.Scanner; import java.util.Scanner;
/** /**
@ -21,26 +22,43 @@ public class payroll {
String employeeName; String employeeName;
double hoursWorked; double hoursWorked;
double hourlyPayRate; double hourlyPayRate;
double taxWithholdingRate; double federalTaxWithholdingRate;
double stateTaxWithholdingRate;
double grossPay;
double federalWithholding;
double stateWithholding;
double totalDeduction;
// Prompt for input // Prompt for input
System.out.print("Enter employee's name: "); System.out.print("Enter employee's name: ");
employeeName = input.next(); employeeName = input.next();
System.out.print("Enter the number of hours worked in a week: "); System.out.print("Enter the number of hours worked in a week: ");
hoursWorked = input.nextDouble(); hoursWorked = input.nextDouble();
System.out.print("Enter the hourly pay rate: "); System.out.print("Enter the hourly pay rate: $");
hourlyPayRate = input.nextDouble(); hourlyPayRate = input.nextDouble();
System.out.println("Enter the federal tax witholding rate: "); System.out.print("Enter the federal tax witholding rate (as a decimal, please!): ");
taxWithholdingRate = input.nextDouble(); federalTaxWithholdingRate = input.nextDouble();
System.out.print("Enter the state tax withholding rate (as a decimal, please!): ");
stateTaxWithholdingRate = input.nextDouble();
System.out.println(""); //empty space
// Setup Decimal fomatting
DecimalFormat df = new DecimalFormat("#0.00");
// Calculate // Calculate
grossPay = (hoursWorked * hourlyPayRate);
federalWithholding = (grossPay * federalTaxWithholdingRate);
stateWithholding = (grossPay * stateTaxWithholdingRate);
totalDeduction = (grossPay - (federalWithholding + stateWithholding));
// Print output // Print output
System.out.println("Employee Name: "+employeeName); System.out.println("Employee Name: "+employeeName);
System.out.println("Hours Worked: "+hoursWorked); System.out.println("Hours Worked: "+hoursWorked);
System.out.println("Pay Rate:"+ hourlyPayRate); System.out.println("Pay Rate: $"+ df.format(hourlyPayRate));
System.out.println("Gross Pay: $"+df.format(grossPay));
System.out.println("Deductions:");
System.out.println("\t"+"Federal Withholding ("+ (federalTaxWithholdingRate * 100.0)+"%):$"+df.format(federalWithholding));
System.out.println("\t"+"State Withholding ("+ (stateTaxWithholdingRate * 100.0)+"%):$"+df.format(stateWithholding));
System.out.println("Total Deduction: $"+df.format(totalDeduction));
} }
} }