首页 上海市计算机等级考试二级(Java)-程序调试与程序填空

上海市计算机等级考试二级(Java)-程序调试与程序填空

举报
开通vip

上海市计算机等级考试二级(Java)-程序调试与程序填空编程题 按指定的要求编写程序段, 1.编写一个程序,把六个按钮分别标识为‘A’至‘F’,并排列成一行。 参考程序: import java.awt.*; public class MyClass { public static void main(String args[]) { String[] labels = {"A","B","C","D","E","F"}; Window win =  new Frame(); win.setLayout(new GridLayout(1,6)); for(int i=...

上海市计算机等级考试二级(Java)-程序调试与程序填空
编程 快递公司问题件快递公司问题件货款处理关于圆的周长面积重点题型关于解方程组的题及答案关于南海问题 按指定的要求编写程序段, 1.编写一个程序,把六个按钮分别标识为‘A’至‘F’,并排列成一行。 参考程序: import java.awt.*; public class MyClass { public static void main(String args[]) { String[] labels = {"A","B","C","D","E","F"}; Window win =  new Frame(); win.setLayout(new GridLayout(1,6)); for(int i=0;i < labels.length;i++) win.add(new Button(labels[i])); win.pack();    win.setVisible(true); } } 【解析】该题目的知识点在于图形用户界面设计中的布局设计,只能采用GridLayout的方式,不能采用默认的FlowLayout布局方式 2.设计一个applet,加载和显示图象“student.gif”。图像文件与包含applet的HTML文件在同一个目录下。 参考程序: import java.awt.*; import java.applet.*; public class Mypicture extends java.applet.Applet{ Image image; public void init (){ image=getImage(getDocumentBase(),"Student.gif"); } public void paint(Graphics g){ g.drawImage(image,0,0, this ); } } 【解析】该题要求掌握如何在applet中显示图像文件的编程能力,具体可参照参考教材第十章。 3. 编写removeRandChar() 方法 快递客服问题件处理详细方法山木方法pdf计算方法pdf华与华方法下载八字理论方法下载 ,该方法有两个参数,类型分别是String和int,第二个参数 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 示从第一个参数指定的字符串中删除字符的个数。删除哪个字符由随机数决定。如果第二个参数比第一个参数指定的字符串长度大,则该方法返回空字符串。 removeRandChar()方法必须包括调用removeSingChar()方法,该方法定义在test4_1应用程序中。 例如执行完整的test4_1应用程序两次后,产生如下的输出: C:\> java test4_1 Remove 3 random characters from INTERESTING: INEETING Remove 6 random characters from INTERESTING: EESTN C:\> java test4_1 Remove 3 random characters from INTERESTING: ITERETIN Remove 6 random characters from INTERESTING: IEESG 下面是不包括removeRandChar()方法的test4_1应用程序: public class test4_1{ public static void main(String[] args) { String word1 = removeRandChar("INTERESTING", 3); System.out.println("Remove 3 random characters from INTERESTING: " + word1); word1 = removeRandChar("INTERESTING", 6); System.out.println("Remove 6 random characters from INTERESTING: " + word1); } /** This method removes the character at position: indexNum, from the String: str, and returns the resulting String. */ private static String removeSingChar(String str, int indexNum) { return str.substring(0,indexNum) + str.substring(indexNum+1); } …… } 参考程序: private static String removeRandChar(String str,  int howMany){ if (str.length() <= howMany) return ""; int randNo; for(int j=0; j other.examMark) System.out.println(name + " did better than " + other.name); else System.out.println(name + " did worse than " + other.name); } } 要求完成test4_3的编程,它将创建两个Student对象并调用相应的方法,产生的输出如下所示: C:\> java test4_3 张楠 got 70 in the test and 85 in the exam 李浩 got 80 in the test and 90 in the exam 李浩's exam mark changed to 40 李浩 did worse than 张楠 注意不能使用任何System.out.print() 或 System.out.println()语句,产生的输出只需简单地调用所创建的Student对象的对应方法。 public class test4_3 { public static void main(String[] args) { Student student1; Student student2; …… } } 参考程序: student1 = new Student("张楠", 70, 85); student2 = new Student("李浩", 80, 90); student1.displayInfo(); student2.displayInfo(); student2.setExamMark(40); student2.compareTo(student1); 【解析】该题考核的重点是面向对象程序设计的基本应用:对象的声明与创建,以及根据需求调用实例方法。 5.编写change( ) 方法,该方法有一个参数,类型为int,通过方法,计算并输出由给定参数(元)的人民币兑换成一元、两元、五元的所有 方案 气瓶 现场处置方案 .pdf气瓶 现场处置方案 .doc见习基地管理方案.doc关于群访事件的化解方案建筑工地扬尘治理专项方案下载 。 例如当用户输入10,执行Test4_1应用程序后,产生如下的输出: import java.io.*; public class Test4_1{ public static void main(String args[]) throws IOException { int money; String str; BufferedReader buf; buf=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Input an integer:"); str=buf.readLine();                              money=Integer.parseInt(str);             
本文档为【上海市计算机等级考试二级(Java)-程序调试与程序填空】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_995397
暂无简介~
格式:doc
大小:25KB
软件:Word
页数:9
分类:计算机考试
上传时间:2019-05-07
浏览量:98