exercise2_15.java

来自「java程序设计 机械工业出版社 书籍代码」· Java 代码 · 共 40 行

JAVA
40
字号
import javax.swing.JOptionPane;public class Exercise2_15 {  public static void main(String args[]) {    // Obtain input    System.out.print("Enter employee's full name: ");    String name = MyInput.readString();        System.out.print("Enter number of hours worked in a week: ");    double hours = MyInput.readDouble();             System.out.print("Enter hourly pay rate: ");    double payRate = MyInput.readDouble();        System.out.print("Enter federal tax withholding rate: ");    double fedTaxWithholdingRate = MyInput.readDouble();    System.out.print("Enter state tax withholding rate: ");    double stateTaxWithholdingRate = MyInput.readDouble();    double grossPay = hours * payRate;    double fedTaxWithholding = grossPay * fedTaxWithholdingRate;    double stateTaxWithholding = grossPay * stateTaxWithholdingRate;    double totalDeduction = fedTaxWithholding + stateTaxWithholding;    double netPay = grossPay - totalDeduction;    // Obtain output    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.print(out);  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?