Java黑皮书课后题第4章:*4.23(金融应用:酬金)编写一个程序,读取下面信息,然后输出一个酬金声明
生活随笔
收集整理的這篇文章主要介紹了
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);} }總結
以上是生活随笔為你收集整理的Java黑皮书课后题第4章:*4.23(金融应用:酬金)编写一个程序,读取下面信息,然后输出一个酬金声明的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java黑皮书课后题第4章:4.22(检
- 下一篇: Java黑皮书课后题第4章:*4.26(