皮皮学,免费搜题
登录
搜题
【简答题】
实验1 算术测试 模板代码 Teacher.java public class Teacher { int numberOne,numberTwo; String operator=""; boolean right; public int giveNumberOne(int n) { numberOne=(int)(Math.random()*n)+1; return numberOne; } public int giveNumberTwo(int n) { numberTwo=(int)(Math.random()*n)+1; return numberTwo; } public String giveOperator() { double d=Math.random(); if(d>=0.5) operator="+"; else operator="-"; return operator; } public boolean getRight(int answer) { if(operator.equals("+")) { if(answer==numberOne+numberTwo) right=true; else right=false; } else if(operator.equals("-")) { if(answer==numberOne-numberTwo) right=true; else right=false; } return right; } } ComputerFrame.java import java.awt.*; import java.awt.event.*; public class ComputerFrame extends Frame implements ActionListener { TextField textOne,textTwo,textResult; Button getProblem,giveAnwser; Label operatorLabel,message; Teacher teacher; ComputerFrame(String s) { super(s); teacher=new Teacher(); setLayout(new FlowLayout()); textOne=【代码1】 //创建textOne,其可见字符长是10 textTwo=【代码2】 //创建textTwo,其可见字符长是10 textResult=【代码3】 //创建textResult,其可见字符长是10 operatorLabel=new Label("+"); message=new Label("你还没有回答呢"); getProblem=new Button("获取题目"); giveAnwser=new Button("确认答案"); add(getProblem); add(textOne); add(operatorLabel); add(textTwo); add(new Label("=")); add(textResult); add(giveAnwser); add(message); textResult.requestFocus(); textOne.setEditable(false); textTwo.setEditable(false); 【代码4】//将当前窗口注册为getProblem的ActionEvent事件监视器 【代码5】//将当前窗口注册为giveAnwser的ActionEvent事件监视器 【代码6】//将当前窗口注册为textResult的ActionEvent事件监视器 setBounds(100,100,450,100); setVisible(true); validate(); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); } public void actionPerformed(ActionEvent e) { if(【代码7】) //判断事件源是否是getProblem { int number1=teacher.giveNumberOne(100); int number2=teacher.giveNumberTwo(100); String operator=teacher.givetOperator(); textOne.setText(""+number1); textTwo.setText(""+number2); operatorLabel.setText(operator); message.setText("请回答"); textResult.setText(null); } if(【代码8】) //判断事件源是否是giveAnwser { String answer=textResult.getText(); try{ int result=Integer.parseInt(answer); if(teacher.getRight(result)==true) { message.setText("你回答正确"); } else { message.setText("你回答错误"); } } catch(NumberFormatException ex) { message.setText("请输入数字字符"); } } textResult.requestFocus(); validate(); } } MainClass.java public class MainClass { public static void main(String args[]) { ComputerFrame frame; frame=【代码9】//创建窗口,其标题为:算术测试 } } 请将代码补充完整,并将运行结果截图写入实验报告。 实验2 布局与日历 1.答案: 【代码1】: pCenter.setLayout(new GridLayout(7,7)); 【代码2】: pCenter.add(titleName[i]); 【代码3】: pCenter.add(labelDay[i]); 【代码4】: add(scrollPane,BorderLayout.CENTER); 【代码5】: add(pNorth,BorderLayout.NORTH); 【代码6】: add(pSouth,BorderLayout.SOUTH); 2.模板代码 CalendarBean.java import java.util.Calendar; public class CalendarBean { String day[]; int year=2005,month=0; public void setYear(int year) { this.year=year; } public int getYear() { return year; } public void setMonth(int month) { this.month=month; } public int getMonth() { return month; } public String[] getCalendar() { String a[]=new String[42]; Calendar 日历=Calendar.getInstance(); 日历.set(year,month-1,1); int 星期几=日历.get(Calendar.DAY_OF_WEEK)-1; int day=0; if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) { day=31; } if(month==4||month==6||month==9||month==11) { day=30; } if(month==2) { if(((year%4==0)&&(year%100!=0))||(year%400==0)) { day=29; } else { day=28; } } for(int i=星期几,n=1;i<星期几+day;i++) { a[i]=String.valueOf(n) ; n++; } return a; } } CalendarFrame.java import java.util.*; import java.awt.*; import java.awt.event.*; import java.applet.*; public class CalendarFrame extends Frame implements ActionListener { Label labelDay[]=new Label[42]; Button titleName[]=new Button[7]; String name[]={"日","一","二","三", "四","五","六"}; Button nextMonth,previousMonth; int year=2006,month=10; CalendarBean calendar; Label showMessage=new Label("",Label.CENTER); public CalendarFrame() { Panel pCenter=new Panel(); 【代码1】 //将pCenter的布局设置为7行7列的GridLayout 布局。 for(int i=0;i<7;i++) { titleName[i]=new Button(name[i]); 【代码2】//pCenter添加组件titleName[i]。 } for(int i=0;i<42;i++) { labelDay[i]=new Label("",Label.CENTER); 【代码3】//pCenter添加组件labelDay[i]。 } calendar=new CalendarBean(); calendar.setYear(year); calendar.setMonth(month); String day[]=calendar.getCalendar(); for(int i=0;i<42;i++) { labelDay[i].setText(day[i]); } nextMonth=new Button("下月"); previousMonth=new Button("上月"); nextMonth.addActionListener(this); previousMonth.addActionListener(this); Panel pNorth=new Panel(), pSouth=new Panel(); pNorth.add(previousMonth); pNorth.add(nextMonth); pSouth.add(showMessage); showMessage.setText("日历:"+calendar.getYear()+"年"+ calendar.getMonth()+"月" ); ScrollPane scrollPane=new ScrollPane(); scrollPane.add(pCenter); 【代码4】// 窗口添加scrollPane在中心区域 【代码5】// 窗口添加pNorth 在北面区域 【代码6】// 窗口添加pSouth 在南区域。 } public void actionPerformed(ActionEvent e) { if(e.getSource()==nextMonth) { month=month+1; if(month>12) month=1; calendar.setMonth(month); String day[]=calendar.getCalendar(); for(int i=0;i<42;i++) { labelDay[i].setText(day[i]); } } else if(e.getSource()==previousMonth) { month=month-1; if(month<1) month=12; calendar.setMonth(month); String day[]=calendar.getCalendar(); for(int i=0;i<42;i++) { labelDay[i].setText(day[i]); } } showMessage.setText("日历:"+calendar.getYear()+"年"+calendar.getMonth()+"月" ); } } CalendarMainClass.java public class CalendarMainClass { public static void main(String args[]) { CalendarFrame frame=new CalendarFrame(); frame.setBounds(100,100,360,300); frame.setVisible(true); frame.validate(); frame.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } } ); } } 请将代码补充完整,并将运行结果截图写入实验报告。 实验3 方程求根 1.答案: 【代码1】: controlButton.addActionListener(this);; 【代码2】: textA.getText() 【代码3】: textB.getText() 【代码4】: textC.getText() 2.模板代码 SquareEquation.java public class SquareEquation { double a,b,c; double root1,root2; public void setA(double a) { this.a=a; } public void setB(double b) { this.b=b; } public void setC(double c) { this.c=c; } public double getRootOne() throws NoRealRootException,NoSquareEquationException { if(a!=0) { double disk=b*b-4*a*c; if(disk>=0) { root1=(-b+Math.sqrt(disk))/(2*a); } else { throw new NoRealRootException("没有实根"); } } else { throw new NoRealRootException("不是二次方程"); } return root1; } public double getRootTwo() throws NoRealRootException,NoSquareEquationException { if(a!=0) { double disk=b*b-4*a*c; if(disk>=0) { root2=(-b-Math.sqrt(disk))/(2*a); } else { throw new NoRealRootException("没有实根"); } } else { throw new NoRealRootException("不是二次方程"); } return root2; } } class NoRealRootException extends Exception { String message; NoRealRootException(String s) { message=s; } public String getMessage() { return message; } } class NoSquareEquationException extends Exception { String message; NoSquareEquationException(String s) { message=s; } public String getMessage() { return message; } } EquationFrame.java import java.awt.*; import java.awt.event.*; public class EquationFrame extends Frame implements ActionListener { SquareEquation equation; TextField textA,textB,textC; TextArea showRoots; Button controlButton; public EquationFrame() { equation=new SquareEquation(); textA=new TextField(8); textB=new TextField(8); textC=new TextField(8); showRoots=new TextArea(); controlButton=new Button("确定"); Panel pNorth=new Panel(); pNorth.add(new Label("二次项系数:")); pNorth.add(textA); pNorth.add(new Label("一次项系数:")); pNorth.add(textB); pNorth.add(new Label("常数项系数:")); pNorth.add(textC); pNorth.add(controlButton); 【代码1】 //当前窗口作为controlButton的ActionEvent事件的监视器 add(pNorth,BorderLayout.NORTH); add(showRoots,BorderLayout.CENTER); setBounds(100,100,630,160); setVisible(true); validate(); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); } public void actionPerformed(ActionEvent e) { try{ double a=Double.parseDouble(【代码2】); //textA调用方法获取其中的文本 double b=Double.parseDouble(【代码3】); //textB调用方法获取其中的文本 double c=Double.parseDouble(【代码4】); // textC调用方法获取其中的文本 equation.setA(a); equation.setB(b); equation.setC(c); textA.setText(""+a); textB.setText(""+b); textC.setText(""+c); showRoots.append("\n 根:"+equation.getRootOne()); showRoots.append(" 根:"+equation.getRootTwo()); } catch(Exception ex) { showRoots.append("\n"+ex+"\n"); } } } EquationMainClass.java public class EquationMainClass { public static void main(String args[]) { EquationFrame frame=new EquationFrame(); } } 请将代码补充完整,并将运行结果截图写入实验报告。 练习1 教材第279页 第三题第(1)小题,模仿教材,9,请在实验报告中描述程序思路,并展示源代码和运行结果。 练习2 教材第280页 第三题第(3)小题,模仿教材例15,请在实验报告中描述程序思路,并展示源代码和运行结果。
拍照语音搜题,微信中搜索"皮皮学"使用
参考答案:
参考解析:
知识点:
.
..
皮皮学刷刷变学霸
举一反三
【判断题】传统的4个比特位表示的数据,可以有16种不同组合,但每次只能取1种。
A.
正确
B.
错误
【简答题】Read passage and fill in the blanks with following words and expession tend to complete real world leave make better use of Do you think that work wi...
【单选题】下列水溶液中 , 酸性最弱的是
A.
0.1mol/L HCl
B.
0.1mol/L HCN(K a =4.93 × 10 -10 )
C.
0.1mol/L HCOOH (K a =1.7 × 10 -4 )
D.
0.1mol/L HAc (K a =1.76 × 10 -5 )
【单选题】下列关于数据库管理技术的发展的描述中,不正确的是( )。
A.
数据库管理技术大致经历了人工管理、文件系统、数据库系统和高级数据库系统 4个阶段
B.
数据库管理技术的4个阶段程序和数据都是独立的
C.
分布式数据库和面向对象数据库管理技术属于高级数据库技术
D.
数据库系统阶段数据库中的数据可以被多个用户、多个应用程序共享
【简答题】your recommendation is of no use at all to those who do not want to listen.
【判断题】Those who are not versed in foreign exchange terminoogy can do a better job if they restrict their use of the expressions"favourable" and "unfavourable" or "appreciate" and "depreciate".
A.
正确
B.
错误
【单选题】下列水溶液中,酸性最弱的是( )
A.
0.1mol/L HCl
B.
0.1mol/L HCN( ( Ka=4.93×10 -10 )
C.
0.1mol/L HCOOH( ( Ka=1.70×10 -4 )
D.
0.1mol/L HAc( ( Ka=1.76×10 -5 )
【单选题】数据库管理技术的发展经历了由低级到高级的过程。分布式数据库、面向对象数据库等新型数据库属于( )。
A.
人工管理阶段
B.
文件系统阶段
C.
数据库系统阶段
D.
高级数据库技术阶段
【单选题】下列水溶液中,酸性最弱的是()
A.
0.1mol/LHCl
B.
0.1mol/LHCN(KA=4.93×10-10)
C.
0.1mol/LHCOOH(KA=1.7×10-4)
D.
0.1mol/LHAC(KA=1.76×10-5)
【简答题】I. Choose the best word and use its proper form to fill in the blank. sketch mystery religious renewable feature monument (4) He was a lovable man , and his teachings can have much for those who do no...
相关题目: