第2章:财务应用程序:工资单

来源:互联网 发布:ttc 轴体 知乎 编辑:程序博客网 时间:2024/04/30 08:16
/** * 财务应用程序:工资单。 * 读入下列信息并打印工资单: * 雇员的名字(Smith)。 * 每周工作的小时数(10)。(hours) * 每小时工资(6.75)。(rate) * 联邦所得税税率(29%)。(federal) (federalrate) * 州所得税税率(9%)。(state) (staterate) * (1)使用控制台进行输入和输出。 * (2)使用对话框获取输入并显示输出。 * 下面是运行示例: * —————————————————————————————————————————————— * | Enter employee`s name: Smith               | * | Enter number of hours worked in a week: 10 | * | Enter pay rate: 6.75                       | * | Enter federal tax withholding rate: 0.20   | * | Enter state tax withholding rate: 0.09     | * | Employee Name: Smith                       | * | Hours Worked: 10.0                         | * | Pay Rate: 6.75                             | * | Gross Pay: 67.5                            | * | Deductions:                                | * | Federal Withhoulding (20.0%): 13.5      | * | State Withhoulding (9.0%): 6.075        | * | Total Deduction: 19.575                 | * | Net Pay: 47.925                            | * —————————————————————————————————————————————— */package Test;import java.util.Scanner;public class T211Scanner {public static void main(String[] args) {Scanner input = new Scanner(System.in);System.out.print("Enter employee`s name: ");String name = input.nextLine();System.out.print("Enter number of hours worked in a week: ");double hours = input.nextInt();System.out.print("Enter pay rate: ");double rate = input.nextDouble();System.out.print("Enter federal tax withholding rate: ");double federal = input.nextDouble();System.out.print("Enter state tax withholding rate: ");double state = input.nextDouble();double pay = hours * rate;double federalrate = pay * federal;double staterate = pay * state;double total = federalrate + staterate;double totalpay = pay - total;System.out.println("Employee Name: " + name);System.out.println("Hours Worked: " + hours);System.out.println("Pay Rate: " + rate);System.out.println("Gross Pay: " + pay);System.out.println("Deductions: \n" + "\tFederal Withhoulding (20.0%): " + federalrate+ "\n\t" + "State Withhoulding (9.0%): " + staterate+ "\n\t" + "Total Deduction: " + total+ "\nNet Pay: " + totalpay);}}


原创粉丝点击