Skip to content

Instantly share code, notes, and snippets.

@jonathan-irvin
Last active August 29, 2015 14:19
Show Gist options
  • Save jonathan-irvin/419528ca5072ec32f420 to your computer and use it in GitHub Desktop.
Save jonathan-irvin/419528ca5072ec32f420 to your computer and use it in GitHub Desktop.
Payroll Project Problem
import java.text.NumberFormat;
import java.util.Scanner;
public class Payroll {
public static void main(String[] args) {
System.out.print("Employee's Name: ");
Scanner input = new Scanner(System.in);
String eName = input.nextLine();
System.out.print("Hours Worked: ");
int hours = input.nextInt();
System.out.print("Pay Rate: ");
double wage = input.nextDouble();
double gross_pay = wage * hours;
System.out.print("Federal Tax Withholding (Decimal): ");
double fedtax = input.nextDouble();
double fedwithhold = gross_pay * fedtax;
System.out.print("State Tax Withholding (Decimal): ");
double statetax = input.nextDouble();
double statewithhold = gross_pay * statetax;
double totalwithhold = fedwithhold + statewithhold;
double netpay = gross_pay - totalwithhold;
NumberFormat formatter = NumberFormat.getCurrencyInstance();
System.out.println("Employee Name: "+eName);
System.out.println("Hours Worked: "+hours);
System.out.println("Pay Rate: "+formatter.format(wage));
System.out.println("Gross Pay: "+formatter.format(gross_pay));
System.out.println("Deductions:");
System.out.println(" Federal Withholding: "+formatter.format(fedwithhold));
System.out.println(" State Withholding: "+formatter.format(statewithhold));
System.out.println(" Total Withheld: "+formatter.format(totalwithhold));
System.out.println("Net Pay: "+formatter.format(netpay));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment