I have a class project where my teacher wants me to use type double for my numbers but it is required that I do not use and special functions or formatting when roudning amounts to the nearest dollar.
Here's what I have so far:
//Variable Declarations
String name;
int hoursWorked;
double hourlyPayRate;
double federalTaxRate;
double stateTaxRate;
double grossPay;
double netPay;
double totalDeduction;
//Getting user inputs
Scanner input = new Scanner(System.in);
System.out.print("Enter employee's name: ");
name = input.next();
System.out.print("Enter number of hours worked in a week: ");
hoursWorked = input.nextInt();
System.out.print("Enter hourly pay rate: ");
hourlyPayRate = input.nextDouble();
System.out.print("Enter federal tax withholding rate: ");
federalTaxRate = input.nextDouble();
System.out.print("Enter state tax withholding rate: ");
stateTaxRate = input.nextDouble();
System.out.println();
//Amount Calculations
grossPay = hoursWorked * hourlyPayRate;
totalDeduction = (grossPay * federalTaxRate) +
(grossPay * stateTaxRate);
//Printing Payroll Statement
System.out.println("Employee Name: " + name);
System.out.println("Hours Worked: " + hoursWorked);
System.out.println("Pay Rate: $" + hourlyPayRate);
System.out.println("Gross Pay: $" + grossPay);
System.out.println("Deductions: ");
System.out.println("\tFederal Withholding (" + (federalTaxRate * 100) +
"%): $" + (grossPay * federalTaxRate));
System.out.println("\tState Withholding (" + (stateTaxRate * 100) +
"%): $" + (grossPay * stateTaxRate));
System.out.println("\tTotal Deduction: $" + totalDeduction);
System.out.println("Net pay: $" + (grossPay - totalDeduction));
And my output would be something similar to this:
Enter employee's name: Bob
Enter number of hours worked in a week: 25
Enter hourly pay rate: 10.30
Enter federal tax withholding rate: .2
Enter state tax withholding rate: .09
Employee Name: Bob
Hours Worked: 25
Pay Rate: $10.3
Gross Pay: $257.5
Deductions:
Federal Withholding (20.0%): $51.5
State Withholding (9.0%): $23.175
Total Deduction: $74.675
Net pay: $182.825
I need the outputs on things like federal witholding, state witholding, total deduction and net pay to be rounded to the nearest penny because these are dollar amounts.