题目
题目概述
*4.23(金融应用:酬金)编写一个程序,读取下面信息,然后输出一个酬金声明:
雇员姓名(如Smith)
每周的工作小时数(如10小时)
每小时的酬金(如9.75美元)
联邦所得税税率(如20%)
州所得税税率(如9%)
运行示例
Enter employee’s name: Smith
Enter number of hours worked in a week: 10
Enter hourly pay rate: 9.75
Enter federal tax withholding rate: 0.20
Enter state tax withholding rate: 0.09
Emplyee Name: Smith
Hours Worked: 10.0
Pay Rate: $9.75
Gross Pay: $97.5
Deductions:
Federal Withholding (20.0%): $19.5
State Withholding(9.0%): $8.77
Total Deduction: $28.27
Net Pay: $69.22
代码
import java.util.Scanner;
public class Test4_23 {
public static void main(String[] args) {
// 接收输入
Scanner input = new Scanner(System.in);
System.out.println("Enter employee's name: ");
String name = input.next();
System.out.println("Enter number of hours worked in a week: ");
double hours = input.nextDouble();
System.out.println("Enter hourly pay rate: ");
double pay = input.nextDouble();
System.out.println("Enter federal tax withholding rate: ");
double fe_tax = input.nextDouble();
System.out.println("Enter state tax withholding rate: ");
double st_tax = input.nextDouble();
// 计算收入
double gross = hours * pay;
double fe_holding = gross * fe_tax;
double st_holding = gross * st_tax;
double tax_total = fe_holding + st_holding;
double net_pay = gross - tax_total;
System.out.println(gross + " " + fe_holding + " " + st_holding + " " + tax_total + " " + net_pay);
// 输出结果
System.out.println("Emplyee Name: "+ name);
System.out.println("Hours Worked: " + hours);
System.out.println("Pay Rate: $" + pay);
System.out.println("Gross Pay: $" + gross);
System.out.println("Deductions:");
System.out.println(" Federal Withholding (" + fe_tax + "%): $" + fe_holding);
System.out.println(" State Withholding (" + st_tax + "%: $" + st_holding);
System.out.println(" Total Deduction: $" + tax_total);
System.out.println("Net Pay: $" + net_pay);
}
}