exercise2_13.java
来自「java程序设计 机械工业出版社 书籍代码」· Java 代码 · 共 53 行
JAVA
53 行
import javax.swing.JOptionPane;public class Exercise2_13 { public static void main(String args[]) { // Obtain input String name = JOptionPane.showInputDialog(null, "Enter employee's full name:", "Exercise2_13 Input", JOptionPane.QUESTION_MESSAGE); String hoursString = JOptionPane.showInputDialog(null, "Enter number of hours worked in a week:", "Exercise2_13 Input", JOptionPane.QUESTION_MESSAGE); double hours = Double.parseDouble(hoursString); String rateString = JOptionPane.showInputDialog(null, "Enter hourly pay rate:", "Exercise2_13 Input", JOptionPane.QUESTION_MESSAGE); double payRate = Double.parseDouble(rateString); String fedTaxWithholdingRateString = JOptionPane.showInputDialog(null, "Enter federal tax withholding rate:", "Exercise2_13 Input", JOptionPane.QUESTION_MESSAGE); double fedTaxWithholdingRate = Double.parseDouble(fedTaxWithholdingRateString); String stateTaxWithholdingRateString = JOptionPane.showInputDialog(null, "Enter state tax withholding rate:", "Exercise2_13 Input", JOptionPane.QUESTION_MESSAGE); double stateTaxWithholdingRate = Double.parseDouble(stateTaxWithholdingRateString); 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:" + " " + hoursString + '\n'; out += "Pay Rate:" + " $" + rateString + '\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); JOptionPane.showMessageDialog(null, out, "Exercise2_13 Output", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?