I'm using Eclipse on an a homework assignment and I'm really struggling. The goal is to write a payroll program that has a user enter their name, hours worked, pay rate, federal and state tax withheld, and then outputs the calculated information of their amounts withheld as well as their net pay.
I used what I was familiar with which is println
statements to show the output but the teacher wants us to use the System.out.printf
function and I can't get it to work at all. If I use println
statements all the values fill but for some reason I can't manage to get the printf
to do the same. What am I missing? If I use the printf
function it gives me the error of
"Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method printf(Locale, String, Object[]) in the type PrintStream is not applicable for the arguments (String, String, String)
at Payrolls.main(Payrolls.java:31)"
Here's my code:
import java.util.Scanner;
public class Payrolls
{
public static void main(String []args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter employee first name: ");
String employeeFirst = input.nextLine();
System.out.print("Enter employee last name: ");
String employeeLast = input.nextLine();
System.out.print("Enter number of hours worked this week: ");
int hoursWorked = input.nextInt();
System.out.print("Enter hourly pay rate of the employee: ");
double payRate = input.nextDouble();
System.out.print("Enter federal tax withholding rate: ");
double fedTax = input.nextDouble();
System.out.print("Enter state tax withholding rate: ");
double stateTax = input.nextDouble();
System.out.println(" ");
System.out.println(" ");
//System.out.printf("%-20s %s\n", employeeFirst, employeeLast);
System.out.println("Name: " + employeeFirst +" " +employeeLast);
System.out.println("Hours Worked:" + hoursWorked);
System.out.println("Pay Rate:" + payRate);
double grossPay;
grossPay = payRate * hoursWorked;
System.out.println("Gross Pay:" + grossPay);
double deductions;
deductions = grossPay * fedTax;
System.out.println("\tDeductions:");
System.out.println("\t\tFederal Witholding %: $" + deductions);
double statTax;
statTax = grossPay * stateTax;
System.out.println("\t\tState Witholding %: $" + statTax);
double totalDeduction;
totalDeduction = deductions + statTax;
System.out.println("\t\tTotal Deduction: $" + totalDeduction);
double netPay;
netPay = grossPay - totalDeduction;
System.out.println("Net Pay:" + netPay);
}
}