Created
November 12, 2017 15:37
-
-
Save gitaficionado/e029cc6cb26c543f5184360dfb7317dd to your computer and use it in GitHub Desktop.
(Financial application: payroll) Write a program that reads the following information and prints a payroll statement: Employee’s name (e.g., Smith) Number of hours worked in a week (e.g., 10) Hourly pay rate (e.g., 9.75) Federal tax withholding rate (e.g., 20%) State tax withholding rate (e.g., 9%) A sample run is shown below: Enter employee's n…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package liang; | |
import java.util.Scanner; | |
public class Payroll { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
// Obtain input | |
System.out.print("Enter employee's name: "); | |
___________________ = input._______(); | |
System.out.print("Enter number of hours worked in a week: "); | |
________________ = ___________________(); | |
System.out.print("Enter hourly pay rate: "); | |
____________________ = _________________; | |
System.out.print("Enter federal tax withholding rate: "); | |
___________fedTaxWithholdingRate = input.____________(); | |
System.out.print("Enter state tax withholding rate: "); | |
_______________________________ = ___________________(); | |
______________________ = hours * payRate; | |
______________________________g = grossPay * fedTaxWithholdingRate; | |
___________________________ = grossPay * stateTaxWithholdingRate; | |
double totalDeduction = _____________________ + __________________; | |
______________________ = _______________ - ___________________; | |
// Obtain output using println | |
// String out = "Employee Name: " + name + "\n\n"; | |
// out += "Hours Worked:" + " " + hours + '\n'; | |
// out += "Pay Rate:" + " $" + payRate + '\n'; | |
// out += "Gross Pay:" + " $" + grossPay + '\n'; | |
// out += "Deductions:\n"; | |
// out += " Federal Withholding (" + fedTaxWithholdingRate * 100 | |
// + "%):" + " $" + (int)(fedTaxWithholding * 100) / 100.0 + '\n'; | |
// out += " State Withholding (" + stateTaxWithholdingRate * 100 + "%):" | |
// + " $" + (int)(stateTaxWithholding * 100) / 100.0 + '\n'; | |
// out += " Total Deduction:" + " $" | |
// + (int)(totalDeduction * 100) / 100.0 + '\n'; | |
// out += "Net Pay:" + " $" + (int)(netPay * 100) / 100.0; | |
System.out.printf("Employee Name: %s\n", name); | |
System.out.printf("Hours Worked: %.2f\n", hours); | |
System.out.printf("Pay Rate: $%.2f\n", payRate); | |
System.out.printf("Gross Pay: $%.2f\n", grossPay); | |
System.out.printf("Deductions: \n"); | |
System.out.printf(" Federal Withholding (%.2f%%): $%.2f\n", | |
fedTaxWithholdingRate * 100, fedTaxWithholding); | |
System.out.printf(" State Withholding (" + stateTaxWithholdingRate * 100 + "%%):" | |
+ " $%.2f\n", stateTaxWithholding); | |
System.out.printf(" Total Deduction:" + " $%.2f\n", totalDeduction); | |
System.out.printf("Net Pay:" + " $%.2f\n", netPay); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment