Java黑皮书课后题第4章:*4.23(金融应用:酬金)编写一个程序,读取下面信息,然后输出一个酬金声明

*4.23(金融应用:酬金)编写一个程序,读取下面信息,然后输出一个酬金声明

题目

题目概述

*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);
    }
}
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值