HW2.11
2024-10-18 16:39:47
控制台:
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); } }
最新文章
- JSTL标签库的使用
- 挤点时间写博客-php&;MySQL实践
- easyui tree获取直接子节点而不获取孙子节点方法
- C++字符数字的编码(Encode)与解码(Decode)
- Servlet&JSP中的知识点
- 解决Windows服务1053错误方法
- javascript 变量转义
- 前端工具 - 15个最佳的 JavaScript 表单验证库
- 2013暑假总结-SB学习
- 关于获取URL中传值的解决方法--升级版
- 主成分分析算法(PCA)
- Kubernetes 持续集成 SpringCloud
- vue组件监听不生效,比深度监听还管用哦
- TCP/IP通信协议
- [Javascript] Check both prop exists and value is valid
- Java实现浏览器端大文件分片上传
- Hbase—— rowkey 过滤器(rowfilter)
- 20154327 Exp7 网络欺诈防范
- Xamarin Visual Studio不识别JDK路径
- 浅析bootstrap原理及优缺点
热门文章
- Codeforces Round #345 (Div. 1) A. Watchmen 模拟加点
- PL/SQL — 函数
- GCC交叉编译链命名
- FatFsVersion0.01源码分析
- <;三>; jQuery 选择器
- 30 个最棒的 jQuery 的拖放插件
- 环信_EaseUI 使用指南
- NGUI所见即所得之UIAtlasMaker , UIAtlas (2)
- 调试Android USB遇到的令人费解的问题
- Tomcat 6.0下配置HTTPS