博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HW2.11
阅读量:4883 次
发布时间:2019-06-11

本文共 3871 字,大约阅读时间需要 12 分钟。

 

控制台:

1 import java.util.Scanner; 2  3 public class Solution 4 { 5     public static void main(String[] args) 6     { 7         Scanner input = new Scanner(System.in); 8  9         System.out.print("Enter employee's name: ");10         String name = input.nextLine();11 12         System.out.print("Enter number of hours worked in a week: ");13         int hoursWorked = input.nextInt();14 15         System.out.print("Enter hourly pay rate: ");16         double hourlyPayRate = input.nextDouble();17 18         System.out.print("Enter federal tax withholding rate: ");19         double federalTax = input.nextDouble();20 21         System.out.print("Enter state tax withholding rate: ");22         double stateTax = input.nextDouble();23 24         input.close();25 26         double grossPay = hoursWorked * hourlyPayRate;27         double federalTaxPay = grossPay * federalTax;28         double stateTaxPay = grossPay * stateTax;29         double totalDeduction = federalTaxPay + stateTaxPay;30         double netPay = grossPay - totalDeduction;31 32         System.out.println("Employee Name: " + name);33         System.out.println("Hours Worked: " + hoursWorked);34         System.out.println("Pay Rate: " + "$" + hourlyPayRate);35         System.out.println("Gross Pay: " + "$" + grossPay);36         System.out.println("Deductions: " + "\n" + 37             "\t" + "Federal Withholding (" + federalTax + "): " + "$" + federalTaxPay +38             "\t" + "State Withholding(" + stateTax + "): " + "$" + stateTaxPay + 39             "\t" + "Total Deduction: " + "$" + totalDeduction);40         System.out.println("Net Pay: " + "$" + netPay);41     }42 }

 

对话框:

1 import javax.swing.JOptionPane; 2  3 public class Solution 4 { 5     public static void main(String[] args) 6     { 7         String name = JOptionPane.showInputDialog(null, "Enter employee's name: ",  8             "Employee Name", JOptionPane.QUESTION_MESSAGE); 9 10         String hoursWorkedString = JOptionPane.showInputDialog(null, "Enter number of hours worked in a week: ", 11             "Work Hour", JOptionPane.QUESTION_MESSAGE);12         int hoursWorked = Integer.parseInt(hoursWorkedString);13 14         String hourlyPayRateString = JOptionPane.showInputDialog(null, "Enter hourly pay rate: ", 15             "Hourly Pay Rate", JOptionPane.QUESTION_MESSAGE);16         double hourlyPayRate = Double.parseDouble(hourlyPayRateString);17 18         String federalTaxString = JOptionPane.showInputDialog(null, "Enter federal tax withholding rate: ", 19             "Federal Tax", JOptionPane.QUESTION_MESSAGE);20         double federalTax = Double.parseDouble(federalTaxString);21 22         String stateTaxString = JOptionPane.showInputDialog(null, "Enter state tax withholding rate: ", 23             "State Tax", JOptionPane.QUESTION_MESSAGE);24         double stateTax = Double.parseDouble(stateTaxString);25 26         double grossPay = hoursWorked * hourlyPayRate;27         double federalTaxPay = grossPay * federalTax;28         double stateTaxPay = grossPay * stateTax;29         double totalDeduction = federalTaxPay + stateTaxPay;30         double netPay = grossPay - totalDeduction;31 32         String output = "Employee Name: " + name + "\n" +33             "Hours Worked: " + hoursWorked + "\n" +34             "Pay Rate: " + "$" + hourlyPayRate + "\n" + 35             "Gross Pay: " + "$" + grossPay + "\n" + 36             "Deductions: " + "\n" + 37             "\t" + "Federal Withholding (" + federalTax + "): " + "$" + federalTaxPay + "\n" +38             "\t" + "State Withholding(" + stateTax + "): " + "$" + stateTaxPay + "\n" + 39             "\t" + "Total Deduction: " + "$" + totalDeduction + "\n" +40             "Net Pay: " + "$" + netPay;41 42         JOptionPane.showMessageDialog(null, output);43     }44 }

 

转载于:https://www.cnblogs.com/wood-python/p/5745955.html

你可能感兴趣的文章
我遇到的jsp 传递参数 出现乱码的情况(项目统一编码utf-8)
查看>>
免安装版TOMCAT配置及问题解决方法
查看>>
SharePoint管理中心配置内容数据库
查看>>
P2P网贷中的4种理財业务模式
查看>>
flume原理
查看>>
【转载】C#防SQL注入过滤危险字符信息
查看>>
一:两数之和
查看>>
Innodb中的事务隔离级别和锁的关系
查看>>
CentOS 7 删除 virbr0 虚拟网卡
查看>>
linux下保护视力、定时强制锁定软件: Workrave
查看>>
使用shell脚本自动化对硬盘进行分区
查看>>
Linux-重装系统之phpmyadmin安装
查看>>
POJ 1426 Find The Multiple(打表)
查看>>
PHP 在xampp中为项目访问配置本地域名的方法
查看>>
你常用但是你经常得搜的一些mysql命令
查看>>
第二组第八周学习心得
查看>>
SQL Server 中对XML数据的五种基本操作
查看>>
使用nginx实施负载均衡
查看>>
用户·角色·权限·表
查看>>
Winsock出错引起的断网
查看>>