JAVA课程设计 小学数学算数测试软件.docx
《JAVA课程设计 小学数学算数测试软件.docx》由会员分享,可在线阅读,更多相关《JAVA课程设计 小学数学算数测试软件.docx(29页珍藏版)》请在冰点文库上搜索。
![JAVA课程设计 小学数学算数测试软件.docx](https://file1.bingdoc.com/fileroot1/2023-7/8/c1c61a6c-5d3e-4baf-99a2-a301bbab34bb/c1c61a6c-5d3e-4baf-99a2-a301bbab34bb1.gif)
JAVA课程设计小学数学算数测试软件
软件学院
课程设计报告书
课程名称面向对象程序设计
设计题目小学数学测试软件
专业班级
学号
姓名
指导教师
2014年6月
1设计时间
2014年6月17日—20日
2设计目的
《面向对象程序设计》这门学科需要很强的实践动手能力,本次课程设计旨在锻炼自己的动手能力。
加强JAVA语言的应用能力,全面地学习JAVA语言,熟练编写过程。
掌握基本的实验设计方法,以及基本的应用知识。
3设计题目
设计一个小学算术运算测试软件
4设计任务
4、1基本功能
设计GUI界面,通过选择不同运算符(如加减法、乘除法)及运算数的范围(如10以内、100以内等)后随机产生指定书目(10道,20道等)的运算式子,测试提交后自动评分,根据不同测试结果给出提示(如“你真棒”,”继续努力”等)。
5设计内容
5.1问题描述
对于小学生来说,涉及到的数学运算不多,可以设计一个简单的数学运算测试小软件,来练习算术能力,帮助小学生提高运算技巧。
5.1.1基本要求
设计GUI界面,通过选择不同运算符(如加减法、乘除法)及运算数的范围(如10以内、100以内等)后随机产生指定书目(10道,20道等)的运算式子,测试提交后自动评分,根据不同测试结果给出提示(如“你真棒”,”继续努力”等)。
5.2总体设计
5.2.1包的描述
本程序导入了
java.awt.BorderLayout包,
java.awt.Color包,
java.awt.GridLayout包,
java.awt.event.ActionEvent包,
java.awt.event.ActionListener包,
java.text.DecimalFormat包,
javax.swing.JButton包,
javax.swing.JFrame包,
javax.swing.JPanel包,
javax.swing.JTextField包
5.2.2类的设计
定义一个主类,在里面定义构造方法,还有监听器等组件
5.3详细设计
5.3.1主要组件设计
根据要求软件要能选择运算符号,还有运算范围。
能根据测试者做对的题数给予鼓励
运算符号选择界面,有四种符号,都分别用单选按钮来实现,再注册事件监听器。
运算范围界面,有两种,同样用单选按钮来实现,注册事件监听器。
题号,正确题数,题目分别是三个标签。
答案输入框是一个文字输入框。
开始测试,完成测试,结束测试是三个注册了事件监听器的按钮。
5.3.2页面设计
本软件采用了GirdLayout(4,6)布局设计组件的排布
界面图
5.4测试与分析
举几个例子
1.选择10以内的加法进行测试,运行图见5-4-1。
图5-4-1
选择100以内的乘法运算,运行图见5-4-2。
图5-4-2
完成测试,运行图见5-4-3。
图5-4-3
测试没及格,运行图见5-4-4。
图5-4-4
5.5程序代码
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
classEnglishGameextendsJFrameimplementsActionListener,ItemListener
{
publicJLabeljlQuestion1;//题目标题
publicJLabeljlQuestion2;//题目内容
publicJLabeljlAnswer;//答案标题
publicJLabeljlW;//题号
publicJLabeljlT;//正确数
publicJButtonjbStart;//开始游戏
publicJButtonjbEnd;//停止游戏
publicJButtonjbExit;//退出游戏
publicJTextFieldjtfAnswer;//输入答案
publicintm,n,l,answer,trueAnswer,x,y=6,a=0,b=0;//随机数m、n,计数参数
publicJRadioButtonradioButton1;
publicJRadioButtonradioButton2;
publicJRadioButtonradioButton3;
publicJRadioButtonradioButton4;
publicJRadioButtonradioButton5;
publicJRadioButtonradioButton6;
publicButtonGroupgroup1;
publicButtonGroupgroup2;
publicEnglishGame()//构造函数,设计面板
{
this.radioButton1=newJRadioButton("加法运算+");
radioButton1.addItemListener(this);
this.radioButton2=newJRadioButton("减法运算-");
radioButton2.addItemListener(this);
this.radioButton3=newJRadioButton("乘法运算*");
radioButton3.addItemListener(this);
this.radioButton4=newJRadioButton("除法运算/");
radioButton4.addItemListener(this);
this.group1=newButtonGroup();
group1.add(radioButton1);
group1.add(radioButton2);
group1.add(radioButton3);
group1.add(radioButton4);
radioButton1.addItemListener(this);
radioButton2.addItemListener(this);
radioButton3.addItemListener(this);
radioButton4.addItemListener(this);
this.radioButton5=newJRadioButton("10以内的运算");
this.radioButton6=newJRadioButton("100以内的运算");
this.group2=newButtonGroup();
group2.add(radioButton5);
group2.add(radioButton6);
radioButton5.addItemListener(this);
radioButton6.addItemListener(this);
this.x=0;//参数初始化
this.trueAnswer=0;
this.setTitle("小学生算术运算测试软件");//控件初始化
this.setLayout(newGridLayout(4,6));//7行2列布局
this.jlQuestion1=newJLabel();
jlQuestion1.setText("题目:
");
this.jlQuestion2=newJLabel();
this.jlAnswer=newJLabel();
jlAnswer.setText("答案:
");
//ImageIconicon=newImageIcon("QQ图片大兵.png");
this.jbStart=newJButton("开始测试");
jbStart.addActionListener(this);//添加事件监听器
this.jbEnd=newJButton("完成测试");
jbEnd.setEnabled(false);//开始时不可用
jbEnd.addActionListener(this);//添加事件监听器
this.jbExit=newJButton("退出游戏");
jbExit.addActionListener(this);//添加事件监听器
this.jtfAnswer=newJTextField();
jlW=newJLabel();
jlW.setText("题号:
"+x);
jlT=newJLabel();
jlT.setText("正确提交:
"+trueAnswer);
//控件第一行
this.add(newJLabel("请选择运算符:
"));
this.add(radioButton1);
this.add(radioButton2);
this.add(radioButton3);
this.add(radioButton4);
//控件第二行
this.add(newJLabel("请选择运算范围:
"));
this.add(radioButton5);
this.add(newJLabel());
this.add(newJLabel());
this.add(radioButton6);
//控件第三行
this.add(jlW);//添加控件题号1
this.add(jlT);//正确数2
this.add(newJLabel());
this.add(jlQuestion1);//题目标题2
this.add(jlQuestion2);//题目内容3
//控件第四行
this.add(jbStart);//开始游戏
this.add(jbEnd);//停止游戏
this.add(jbExit);//退出游戏
this.add(jlAnswer);//答案标题4
this.add(jtfAnswer);//输入答案5
}
publicvoidcreatQuestion1()//新建题目,10以内加法
{
this.m=(int)(Math.random()*11);//随机运算数
this.n=(int)(Math.random()*11);
answer=m+n;//加法结果
this.jlQuestion2.setText(m+""+"+"+n+"=?
");//使label显示题目内
}
publicvoidcreatQuestion2()//新建题目,10以内减法
{
this.m=(int)(Math.random()*11);//随机运算数
this.n=(int)(Math.random()*11);
answer=m-n;//减法结果
this.jlQuestion2.setText(m+""+"-"+n+"=?
");//使label显示题目内容
}
publicvoidcreatQuestion3()//新建题目,10以内乘法
{
this.m=(int)(Math.random()*11);//随机运算数
this.n=(int)(Math.random()*11);
answer=m*n;//乘法结果
this.jlQuestion2.setText(m+""+"*"+n+"=?
");//使label显示题目内容
}
publicvoidcreatQuestion4()
{//新建题目,10以内除法
this.m=(int)(Math.random()*11);//随机运算数
this.n=(int)(Math.random()*11);
answer=(int)(m/n);//除法结果
this.jlQuestion2.setText(m+""+"/"+n+"=?
");//使label显示题目内容
}
publicvoidcreatQuestion5()
{//新建题目,100以内加法
this.m=(int)(Math.random()*101);//随机运算数
this.n=(int)(Math.random()*101);
answer=m+n;//加法结果
this.jlQuestion2.setText(m+""+"+"+n+"=?
");//使label显示题目内容
}
publicvoidcreatQuestion6()
{//新建题目,100以内加减法
this.m=(int)(Math.random()*101);//随机运算数
this.n=(int)(Math.random()*101);
answer=m-n;//减法结果
this.jlQuestion2.setText(m+""+"-"+n+"=?
");//使label显示题目内容
}
publicvoidcreatQuestion7()
{//新建题目,100以内乘法
this.m=(int)(Math.random()*101);//随机运算数
this.n=(int)(Math.random()*101);
answer=m*n;//乘法结果
this.jlQuestion2.setText(m+""+"*"+n+"=?
");//使label显示题目内容
}
publicvoidcreatQuestion8()
{//新建题目,100以内除法
this.m=(int)(Math.random()*101);//随机运算数
this.n=(int)(Math.random()*101);
answer=(int)(m/n);//除法结果
this.jlQuestion2.setText(m+""+"/"+n+"=?
");//使label显示题目内容
}
publicvoidtest()
{//检测函数,检测是否做到10道题
if(this.x==y)
{//如果做够数目
jlW.setText("题号:
0");//界面初始化
jlT.setText("正确提交:
0");
jbStart.setText("开始测试");
this.jtfAnswer.setText("");
this.jlQuestion2.setText("");
if(trueAnswer>(int)(y*0.6))
{
JOptionPane.showMessageDialog(null,"你真棒,及格了!
!
!
题目数:
"+y+",测试得分:
"+(10*trueAnswer),"",JOptionPane.INFORMATION_MESSAGE);//弹出统计对话框
}
else
{
JOptionPane.showMessageDialog(null,"努力吧,小盆友,沒及格题目数:
"+y+",测试得分:
"+(10*trueAnswer),"",JOptionPane.INFORMATION_MESSAGE);//弹出统计对话框
}
x=0;//数据初始化
trueAnswer=0;
jbStart.setEnabled(true);//设置对应按钮是否可用
jbEnd.setEnabled(false);
}
}
publicvoidshowMe()//窗体显示函数
{
this.setSize(800,500);//窗体大小
this.setVisible(true);//窗体可见
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//窗体关闭方式
}
publicvoiditemStateChanged(ItemEvente){
if(e.getSource()==radioButton1){
a=1;
}
elseif(e.getSource()==radioButton2){
a=2;
}
elseif(e.getSource()==radioButton3){
a=3;
}
elseif(e.getSource()==radioButton4){
a=4;
}
elseif(e.getSource()==radioButton5){
b=1;
}
elseif(e.getSource()==radioButton6){
b=2;
}
}
publicvoidactionPerformed(ActionEvente)//事件处理
{
if(e.getSource()==jbStart)//开始游戏或下一题按钮
{
if((jbStart.getText()=="开始测试"))//按钮为开始游戏
{
jbStart.setText("第一题");
jbEnd.setEnabled(true);//设置按钮可用
x++;
jlW.setText("题号:
"+x);
jbEnd.setEnabled(true);//设置按钮可用
}
elseif((a==0)&&(b==0)){
JOptionPane.showMessageDialog(null,"请先选择运算符号和运算范围","",JOptionPane.INFORMATION_MESSAGE);//提示正确
}
elseif((jbStart.getText()=="第一题")&&(a==1)&&(b==1))
{
creatQuestion1();
jbStart.setText("下一题");
}
elseif((jbStart.getText()=="第一题")&&(a==2)&&(b==1))
{
creatQuestion2();
jbStart.setText("下一题");
}
elseif((jbStart.getText()=="第一题")&&(a==3)&&(b==1))
{
creatQuestion3();
jbStart.setText("下一题");
}
elseif((jbStart.getText()=="第一题")&&(a==4)&&(b==1))
{
creatQuestion4();
jbStart.setText("下一题");
}
elseif((jbStart.getText()=="第一题")&&(a==1)&&(b==2))
{
creatQuestion5();
jbStart.setText("下一题");
}
elseif((jbStart.getText()=="第一题")&&(a==2)&&(b==2))
{
creatQuestion6();
jbStart.setText("下一题");
}
elseif((jbStart.getText()=="第一题")&&(a==3)&&(b==2))
{
creatQuestion7();
jbStart.setText("下一题");
}
elseif((jbStart.getText()=="第一题")&&(a==4)&&(b==2))
{
creatQuestion8();
jbStart.setText("下一题");
}
elseif((jbStart.getText()=="第一题")&&(a==1)&&(b==1))
{
creatQuestion1();
jbStart.setText("下一题");
}
elseif((jbStart.getText()=="下一题")&&(a==1)&&(b==1))
{
intq=Integer.parseInt(jtfAnswer.getText());
System.out.println(answer);
System.out.println(trueAnswer);
try{
if(q==answer)//答案正确
{
trueAnswer++;//正确回答数增一
creatQuestion1();//新建题目
x++;
jlW.setText("题号:
"+x);
jlT.setText("正确提交:
"+trueAnswer);
test();//判断题目总数
this.jtfAnswer.setText("");//答案输入框置空
}
else
{//答案错误
System.out.println("chuo");
x++;
jlW.setText("题号:
"+x);
jlT.setText("正确提交:
"+trueAnswer);
test();//判断题目总数
this.jtfAnswer.setText("");
}
}
catch(NumberFormatExceptionnfe)
{//转换异常处理
JOptionPane.showMessageDialog(null,"输入有误!
","",JOptionPane.ERROR_MESSAGE);//提示有误
}
jlW.setText("题号:
"+x);
jlT.setText("正确提交:
"+trueAnswer);
test();//测试题目总数是否够10
jlW.setText("题号:
"+x);
jlT.setText("正确提交:
"+trueAnswer);
}
elseif((jbStart.getText()=="下一题")&&(a==2)&&(b==1))
{intq