Java实验报告_实验一_.docx





《Java实验报告_实验一_.docx》由会员分享,可在线阅读,更多相关《Java实验报告_实验一_.docx(31页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、【实验名称】实验1 Java程序设计基础【实验目标】1、学习和掌握Java程序的基本结构。 2、学习和掌握Java程序的基本开发过程和方法。 3、学习和掌握程序设计的基本开发步骤。 4、学习和掌握Java程序的基本输入、输出方法。 5、学习和掌握Java程序设计的基本技.【实验日期和时间记录】2014.4.18-2014.4.26 1.创建、编译和执行Welcome.java。【实验预习】练习利用Java输出简单语句。【实验过程及结果记录】public class Welcomepublic static void main(String args)System.out.println(“Wl
2、ecome to Java!”); 2、(财务应用程序:工资单)编写程序,读入工资基本信息并打印工资单。编写两种版本的程序,依次使用控制台实现输入输出和GUI实现输入输出。运行效果可参见图1和图2。【实验预习】练习GUI输入输出,键盘输入,存在一个变量里面,整体输出。【实验过程及结果记录】控制台界面/* * (#)ComputeAndShowSolary.java * * * author * version 1.00 2014/4/12 */ import java.util.Scanner;/ public class ComputeAndShowSolary public static
3、void main(String args) /input section System.out.print(Enter employees name:);/Promt the user to enter a name Scanner input= new Scanner(System.in); String name=input.nextLine();/input the name System.out.print(Enter number of hours worked in a week:);/Promt the user to enter number of hours double
4、workhour=input.nextDouble();/input the hour System.out.print(Enter hourly pay rate:);/Promt the user to enter the rate double payrate=input.nextDouble();/input the rate System.out.print(Enter federal tax Withholding rate:);/Promt the user to enter the federal tax rate double federalrate=input.nextDo
5、uble();/input the federal tax rate System.out.print(Enter state tax Withholding rate:);/promt the user to enter the state tax rate double staterate=input.nextDouble();/inout the state tax rate /output section System.out.println(雇员姓名: +name);/output employees name System.out.println(工作小时数: +workhour)
6、;/output hours worked System.out.println(每小时工资数: +$+payrate);/output pay rate System.out.println(工资总收入: +$+payrate*workhour);/output payrate System.out.println(所纳税款:);/output Deductions System.out.println(联邦税+(+federalrate*100+%+)+: +$+workhour*payrate*federalrate); System.out.println(州税+(+staterate
7、*100+%+)+: +$+workhour*payrate*staterate); System.out.printf(总纳税: +$); System.out.printf(%.2fn,workhour*payrate*(0.2+0.09); System.out.printf(净收入: +$); System.out.printf(%.2f,workhour*payrate*(1.0-0.2-0.09); GUI界面/* * (#)ComputeAndShowSolaryWithGUI.java * * * author * version 1.00 2014/4/12 */import
8、 javax.swing.JOptionPane;public class ComputeAndShowSolaryWithGUI public static void main(String args) /input section String namestring=JOptionPane.showInputDialog(Enter employees name:); String hoursstring=JOptionPane.showInputDialog(Enter numbers of hours worked in a week:); int hours=Integer.pars
9、eInt(hoursstring); String payratestring=JOptionPane.showInputDialog(Enter hourly pay rate:); double payrate=Double.parseDouble(payratestring); String federalstring=JOptionPane.showInputDialog(Enter federal tax withholding rate:); double federal=Double.parseDouble(federalstring); String statestring=J
10、OptionPane.showInputDialog(Enter state tax withholding rate:); double state=Double.parseDouble(statestring); /output section JOptionPane.showMessageDialog(null, 雇员姓名: +namestring+ n工作小时数:+hours+ n每小时工资数:+$+payrate+ n工资总收入:+ $+payrate*hours+ n所纳税款:+ n 联邦税(20.0%):+$+hours*payrate*0.2+ n 州税(9.0%):+$+(i
11、nt)(hours*payrate*0.09*100)/100.0+ n 总纳税:+$+(int)(hours*payrate*(0.2+0.09)*100)/100.00+ n净收入:+$+(int)(hours*payrate*(1.0-0.2-0.09)*100)/100.00 ); 3、(财务应用程序:计算税款)按照表1,基于纳税人的身份和可征税收入,编写程序,计算某个纳税人的纳税额。比如,计算一个收入美元的单身纳税人的纳税额。程序的运行效果见图3。 说明:题目来源,编程练习3.13(P85)和程序清单3-6(P68)。程序设计的基本步骤,参见2.2小节(P18)和教材P84给出的教学
12、注意。解决方案的选择模型,参见授课ppt文稿。 【实验预习】练习if语句和基本运算语句【实验过程及结果记录】import java.util.Scanner;public class ComputeTax public static void main(String args) System.out.println(0-单身纳税人。1-已婚共同纳税人或证实的鳏寡,2-已婚单独纳税人,3-家庭户主纳税人); System.out.print(Enter the filing status:); Scanner input=new Scanner(System.in); int choice=in
13、put.nextInt(); System.out.print(Enter the taxable income:); double income=input.nextDouble(); double tax=0; if(0=choice) if(0=income&income=8350) tax=income*0.1; else if(8351=income&income=33950) tax=8350*0.1+(income-8350)*0.15; else if(33951=income&income=82250) tax=8350*0.1+(33950-8350)*0.15+(inco
14、me-33950)*0.25; else if(82251=income&income=) tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(income-82250)*0.28; else if(=income&income=) tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(-82250)*0.28+(income-)*0.33; else if(=income) tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(-82250)*0.
15、28+(- )*0.33+(income-)*0.35; if(1=choice) if(0=income&income=16700) tax=income*0.1; else if(16701=income&income=67900) tax=16700*0.1+(income-16700)*0.15; else if(67901=income&income=) tax=16700*0.1+(67900-16700)*0.15+(income-67900)*0.25; else if(=income&income=) tax=16700*0.1+(67900-16700)*0.15+(-67
16、900)*0.25+(income-13751)*0.28; else if(=income&income=) tax=16700*0.1+(67900-16700)*0.15+(-67900)*0.25+(-13751)*0.28+ (income-)*0.33; else if(=income) tax=16700*0.1+(67900-16700)*0.15+(-67900)*0.25+(-13750)*0.28+ (-)*0.33+(income-)*0.35; if(2=choice) if(0=income&income=8350) tax=income*0.1; else if(
17、8351=income&income=33950) tax=8350*0.1+(income-8350)*0.15; else if(33951=income&income=67525) tax=8350*0.1+(33950-8350)*0.15+(income-33950)*0.25; else if(68526=income&income=) tax=8350*0.1+(33950-8350)*0.15+(68525-33950)*0.25+(income-68525)*0.28; else if(=income&income=) tax=8350*0.1+(33950-8350)*0.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 实验 报告

限制150内