控制台:

 import java.util.Scanner;

 public class Solution
 {
     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: ");
         int hoursWorked = input.nextInt();

         System.out.print("Enter hourly pay rate: ");
         double hourlyPayRate = input.nextDouble();

         System.out.print("Enter federal tax withholding rate: ");
         double federalTax = input.nextDouble();

         System.out.print("Enter state tax withholding rate: ");
         double stateTax = input.nextDouble();

         input.close();

         double grossPay = hoursWorked * hourlyPayRate;
         double federalTaxPay = grossPay * federalTax;
         double stateTaxPay = grossPay * stateTax;
         double totalDeduction = federalTaxPay + stateTaxPay;
         double netPay = grossPay - totalDeduction;

         System.out.println("Employee Name: " + name);
         System.out.println("Hours Worked: " + hoursWorked);
         System.out.println("Pay Rate: " + "$" + hourlyPayRate);
         System.out.println("Gross Pay: " + "$" + grossPay);
         System.out.println("Deductions: " + "\n" +
             "\t" + "Federal Withholding (" + federalTax + "): " + "$" + federalTaxPay +
             "\t" + "State Withholding(" + stateTax + "): " + "$" + stateTaxPay +
             "\t" + "Total Deduction: " + "$" + totalDeduction);
         System.out.println("Net Pay: " + "$" + netPay);
     }
 }

对话框:

 import javax.swing.JOptionPane;

 public class Solution
 {
     public static void main(String[] args)
     {
         String name = JOptionPane.showInputDialog(null, "Enter employee's name: ",
             "Employee Name", JOptionPane.QUESTION_MESSAGE);

         String hoursWorkedString = JOptionPane.showInputDialog(null, "Enter number of hours worked in a week: ",
             "Work Hour", JOptionPane.QUESTION_MESSAGE);
         int hoursWorked = Integer.parseInt(hoursWorkedString);

         String hourlyPayRateString = JOptionPane.showInputDialog(null, "Enter hourly pay rate: ",
             "Hourly Pay Rate", JOptionPane.QUESTION_MESSAGE);
         double hourlyPayRate = Double.parseDouble(hourlyPayRateString);

         String federalTaxString = JOptionPane.showInputDialog(null, "Enter federal tax withholding rate: ",
             "Federal Tax", JOptionPane.QUESTION_MESSAGE);
         double federalTax = Double.parseDouble(federalTaxString);

         String stateTaxString = JOptionPane.showInputDialog(null, "Enter state tax withholding rate: ",
             "State Tax", JOptionPane.QUESTION_MESSAGE);
         double stateTax = Double.parseDouble(stateTaxString);

         double grossPay = hoursWorked * hourlyPayRate;
         double federalTaxPay = grossPay * federalTax;
         double stateTaxPay = grossPay * stateTax;
         double totalDeduction = federalTaxPay + stateTaxPay;
         double netPay = grossPay - totalDeduction;

         String output = "Employee Name: " + name + "\n" +
             "Hours Worked: " + hoursWorked + "\n" +
             "Pay Rate: " + "$" + hourlyPayRate + "\n" +
             "Gross Pay: " + "$" + grossPay + "\n" +
             "Deductions: " + "\n" +
             "\t" + "Federal Withholding (" + federalTax + "): " + "$" + federalTaxPay + "\n" +
             "\t" + "State Withholding(" + stateTax + "): " + "$" + stateTaxPay + "\n" +
             "\t" + "Total Deduction: " + "$" + totalDeduction + "\n" +
             "Net Pay: " + "$" + netPay;

         JOptionPane.showMessageDialog(null, output);
     }
 }

最新文章

  1. JSTL标签库的使用
  2. 挤点时间写博客-php&MySQL实践
  3. easyui tree获取直接子节点而不获取孙子节点方法
  4. C++字符数字的编码(Encode)与解码(Decode)
  5. Servlet&JSP中的知识点
  6. 解决Windows服务1053错误方法
  7. javascript 变量转义
  8. 前端工具 - 15个最佳的 JavaScript 表单验证库
  9. 2013暑假总结-SB学习
  10. 关于获取URL中传值的解决方法--升级版
  11. 主成分分析算法(PCA)
  12. Kubernetes 持续集成 SpringCloud
  13. vue组件监听不生效,比深度监听还管用哦
  14. TCP/IP通信协议
  15. [Javascript] Check both prop exists and value is valid
  16. Java实现浏览器端大文件分片上传
  17. Hbase—— rowkey 过滤器(rowfilter)
  18. 20154327 Exp7 网络欺诈防范
  19. Xamarin Visual Studio不识别JDK路径
  20. 浅析bootstrap原理及优缺点

热门文章

  1. Codeforces Round #345 (Div. 1) A. Watchmen 模拟加点
  2. PL/SQL — 函数
  3. GCC交叉编译链命名
  4. FatFsVersion0.01源码分析
  5. <三> jQuery 选择器
  6. 30 个最棒的 jQuery 的拖放插件
  7. 环信_EaseUI 使用指南
  8. NGUI所见即所得之UIAtlasMaker , UIAtlas (2)
  9. 调试Android USB遇到的令人费解的问题
  10. Tomcat 6.0下配置HTTPS