欢迎来到天天文库
浏览记录
ID:32629133
大小:123.10 KB
页数:11页
时间:2019-02-13
《java程序设计期末考试整理》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Java程序设计期末考试整理(2012・05・27…未完待续)0、(建项目、包、类)在Eclipse中创建JAVA项日,项目名为“学号”+“姓名”,如姓名“张三”,学号“081211199”,则项目名为“081211199张三”。在该项目下创建4个包,包名分别为“1x1”、“1x2”“1x3”“1x4”,分别用于存放以下4个题目的相关程序。0812111XX张三:•“田1x1:•“田1x2:•“田1x3:•“由1x41、(选择结构)计算个人所得税。设某人月收入为X元(X由键盘输入),假设个人所得税征收方法如下:⑴当800vxW1300时,应征税为(x-800)*5%;当13002、800时,应征税为(x-800)*10%;(2)当2800vxW5800时,应征税为(x-800)*15%;当5800800&&x<=1300)3、{System.out.println("您应该交税"+(x・800)*0・5);}elseif(x>1300&&x<=2800){System.outprintlnC*您应该交税"+(x-800)*0.1);}elseif(x>2800&&x<=5800){System.out.println("您应该交税"+(x-800)*0.15);1elseif(x>5800&&x<=28000)System.out.println(n您应该交税n+(x-800)*0.2);elseSystem.out.println(n您应该交税n+(x-800)*0.3);2、(异常处理)案例5.5二进制4、转换成十进制如果出错则抛出异常并进行界常处理使用GUI可视化界血编写importjavax.swing.JOptionPane;〃导入使用的GUIclassMyExceptionextendsExceptionMyException(){super("-进制数据输入异常“);classConvert2tol0{publicvoidconvert(Stringstr)throwsMyExceptionintresult=0;booleanb=true;intlen=strJength();intArr[]=newint[len];for(intj=O;j5、str.charAt(j)-4&if(Arr[j]!=l&&Arr[j]!=0){b=false;break;if(b)for(intj=O;j6、jJ*Math.pow(2Xlen-1-j));JOptionPane.showMessageDialog(null,M二进制数”+str+”转换成十进制后为:"+result,"output",JOptionPane.PLAIN_MESSAGE);}else{thrownewMyException();}}}publicclassConvertExce7、ptionDemo{publicstaticvoidmain(String[]args){Convert2tol0c=newConvert?to10();Stringnumber=JOptionPane.showInputDialog("InputtheNumber");try{c.convert(number);}catch(MyExceptione){JOptionPane.showMessageDialog(null,e.toString(),"output'1,JOptionPane.PLAIN_MESSAGE);1}output}2dMyException:二进制数据输入异第8、确定3>(继承与多态)(3」静态多态方法重载实现)(重载一多态)publicclassOverLoadDemo{publicstaticvoidmain(String[]args){OverLoadDemoo=newOverLoadDemo();o.print(5);o.print(l,2);}publicvoidprint(inta){System.out.println("一个参数"+a);1publicvoidprint(ima,intb
2、800时,应征税为(x-800)*10%;(2)当2800vxW5800时,应征税为(x-800)*15%;当5800800&&x<=1300)
3、{System.out.println("您应该交税"+(x・800)*0・5);}elseif(x>1300&&x<=2800){System.outprintlnC*您应该交税"+(x-800)*0.1);}elseif(x>2800&&x<=5800){System.out.println("您应该交税"+(x-800)*0.15);1elseif(x>5800&&x<=28000)System.out.println(n您应该交税n+(x-800)*0.2);elseSystem.out.println(n您应该交税n+(x-800)*0.3);2、(异常处理)案例5.5二进制
4、转换成十进制如果出错则抛出异常并进行界常处理使用GUI可视化界血编写importjavax.swing.JOptionPane;〃导入使用的GUIclassMyExceptionextendsExceptionMyException(){super("-进制数据输入异常“);classConvert2tol0{publicvoidconvert(Stringstr)throwsMyExceptionintresult=0;booleanb=true;intlen=strJength();intArr[]=newint[len];for(intj=O;j5、str.charAt(j)-4&if(Arr[j]!=l&&Arr[j]!=0){b=false;break;if(b)for(intj=O;j6、jJ*Math.pow(2Xlen-1-j));JOptionPane.showMessageDialog(null,M二进制数”+str+”转换成十进制后为:"+result,"output",JOptionPane.PLAIN_MESSAGE);}else{thrownewMyException();}}}publicclassConvertExce7、ptionDemo{publicstaticvoidmain(String[]args){Convert2tol0c=newConvert?to10();Stringnumber=JOptionPane.showInputDialog("InputtheNumber");try{c.convert(number);}catch(MyExceptione){JOptionPane.showMessageDialog(null,e.toString(),"output'1,JOptionPane.PLAIN_MESSAGE);1}output}2dMyException:二进制数据输入异第8、确定3>(继承与多态)(3」静态多态方法重载实现)(重载一多态)publicclassOverLoadDemo{publicstaticvoidmain(String[]args){OverLoadDemoo=newOverLoadDemo();o.print(5);o.print(l,2);}publicvoidprint(inta){System.out.println("一个参数"+a);1publicvoidprint(ima,intb
5、str.charAt(j)-4&if(Arr[j]!=l&&Arr[j]!=0){b=false;break;if(b)for(intj=O;j6、jJ*Math.pow(2Xlen-1-j));JOptionPane.showMessageDialog(null,M二进制数”+str+”转换成十进制后为:"+result,"output",JOptionPane.PLAIN_MESSAGE);}else{thrownewMyException();}}}publicclassConvertExce7、ptionDemo{publicstaticvoidmain(String[]args){Convert2tol0c=newConvert?to10();Stringnumber=JOptionPane.showInputDialog("InputtheNumber");try{c.convert(number);}catch(MyExceptione){JOptionPane.showMessageDialog(null,e.toString(),"output'1,JOptionPane.PLAIN_MESSAGE);1}output}2dMyException:二进制数据输入异第8、确定3>(继承与多态)(3」静态多态方法重载实现)(重载一多态)publicclassOverLoadDemo{publicstaticvoidmain(String[]args){OverLoadDemoo=newOverLoadDemo();o.print(5);o.print(l,2);}publicvoidprint(inta){System.out.println("一个参数"+a);1publicvoidprint(ima,intb
6、jJ*Math.pow(2Xlen-1-j));JOptionPane.showMessageDialog(null,M二进制数”+str+”转换成十进制后为:"+result,"output",JOptionPane.PLAIN_MESSAGE);}else{thrownewMyException();}}}publicclassConvertExce
7、ptionDemo{publicstaticvoidmain(String[]args){Convert2tol0c=newConvert?to10();Stringnumber=JOptionPane.showInputDialog("InputtheNumber");try{c.convert(number);}catch(MyExceptione){JOptionPane.showMessageDialog(null,e.toString(),"output'1,JOptionPane.PLAIN_MESSAGE);1}output}2dMyException:二进制数据输入异第
8、确定3>(继承与多态)(3」静态多态方法重载实现)(重载一多态)publicclassOverLoadDemo{publicstaticvoidmain(String[]args){OverLoadDemoo=newOverLoadDemo();o.print(5);o.print(l,2);}publicvoidprint(inta){System.out.println("一个参数"+a);1publicvoidprint(ima,intb
此文档下载收益归作者所有