一、计划
1.随机生成10道100以内的小学生加减乘除算式,要求不出现负数
2.当提交页面后,判断结果是否正确,并且,计算出正确率和所用时间
二、需求分析
作为一名一年级小学生的家长,我希望制作一个出题软件,完成100以内的正整数的加减法题随机产生。以便减轻我的家庭负担
三、具体设计
系统开始,随机产生10道加法或者减法,计算完成后,统计做了多少道题,正确率
四、具体编码
package com.yu.project; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridLayout; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import com.yu.jishiqi.jishiqi; import com.yu.tiku.Lianxiti; public class Count extends JFrame { public JPanel miaobiaopanel;//秒表面板 public JPanel xuanpanel;//选择面板 public JPanel Countpanel;//计算面板 public JPanel Buttonpanel;//创建按钮及结果面板 public JPanel Youpanel;//创建右侧面板 public JButton Clearbutton;//创建清空按钮 public JButton Resetbutton;//创建重置按钮 public JButton Printfbutton;//创建打印按钮 public JLabel CountLable;//创建正确率(标签),正确率在标签正呈现 public jishiqi miaobiao; public myRadio myradio; LableAndResult le=null; SomeListener sl=null; Container container = getContentPane(); public Count(Lianxiti lianxiti){ le=new LableAndResult(lianxiti); //初始化按钮 Font font=new Font("微软雅黑",Font.BOLD,40); Clearbutton = new JButton("清空"); Clearbutton.setFont(font); Resetbutton = new JButton("重置"); Resetbutton.setFont(font); Printfbutton = new JButton("打印"); Printfbutton.setFont(font); //设置按钮大小 Clearbutton.setPreferredSize(new Dimension(200, 50)); Resetbutton.setPreferredSize(new Dimension(200, 50)); Printfbutton.setPreferredSize(new Dimension(200, 50)); //初始化计数面板 init(); //初始化按钮面板 Buttonpanel = new JPanel(); Buttonpanel.setLayout(new FlowLayout()); Buttonpanel.setBorder(BorderFactory.createLineBorder(Color.GREEN)); Buttonpanel.add(Clearbutton); CountLable = new JLabel(); CountLable.setPreferredSize(new Dimension(200, 50)); CountLable.setFont(font); CountLable.setBorder(BorderFactory.createLineBorder(Color.BLACK)); CountLable.setHorizontalAlignment(JLabel.CENTER); //将按钮添加至按钮及结果面板中 Buttonpanel.add(Resetbutton); Buttonpanel.add(Printfbutton); JPanel youpanel=new JPanel(); youpanel.add(CountLable,BorderLayout.NORTH); //为计数面板添加标签和文本框 // le.CountLable(Countpanel); //设置窗体属性 setLayout(new BorderLayout()); setBounds(200,10,800,1000); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //计时器 //Countpanel.setBackground(Color.YELLOW); miaobiao=new jishiqi(); miaobiao.startMiaoniao(); miaobiaopanel=miaobiao.get(); container.add(miaobiaopanel); //选择 myradio=new myRadio(); container.add(myradio.get(),BorderLayout.EAST); //将计数面板,按钮面板放置在容器中指定位置 //container.add(Zhongpanel, BorderLayout.CENTER); container.add(Countpanel, BorderLayout.CENTER); container.add(Buttonpanel,BorderLayout.SOUTH); container.add(youpanel, BorderLayout.EAST); //System.out.println(Countpanel.getHeight()); sl=new SomeListener(this); sl.myAddActionLIstener(); } public void init() { Countpanel = new JPanel(); le.CountLable(Countpanel); Countpanel.setLayout(new GridLayout(25, 4,10,10)); container.add(Countpanel, BorderLayout.CENTER); } }
package com.yu.project; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.util.ArrayList; import java.util.List; import javax.swing.BorderFactory; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import com.yu.config.MyConfig; import com.yu.tiku.Lianxiti; public class LableAndResult { public static List<JLabel> tiList = new ArrayList<>();//创建用户输入计算结果的文本框集合 public static List<JTextField> userJieguoList = new ArrayList<>();//答题框 public static List<Integer> trueList = new ArrayList<>();//创建所有题目正确答案集合 private Lianxiti lianxiti = null; private int ji=0; private int ou=0; private int i=0; public LableAndResult(Lianxiti lianxiti) { this.lianxiti=lianxiti; } public void CountLable(JPanel Countpanel){ int tishu=Integer.parseInt(MyConfig.myMap.get("题数")); System.out.println(tishu); for(i=0;i<tishu;i++){ JLabel label = new JLabel(); //重点:在设置布局的条件下,调用setPreferredSize(new Dimension(80, 20))可以设置标签的大小 //重点:而不能调用setsize()方法 label.setPreferredSize(new Dimension(80, 30)); label.setFont(new Font("楷体",Font.BOLD, 30)); label.setBorder(BorderFactory.createLineBorder(Color.WHITE));//设置标签的边界 tiList.add(label);//list为题目(标签)集合,题目在标签中呈现 JTextField textField = new JTextField(4); userJieguoList.add(textField);//list1为用户输入计算结果的文本框集合 } for(i = 0;i<tishu*2;i++){//利用if-else语句来间隔输出标签和文本框 if(i%2 == 0){//如果余数为0,则添加标签 Countpanel.add(tiList.get(ji)); ji++; }else{//如果余数为1,则添加文本框 userJieguoList.get(ou).setFont(new Font("楷体",Font.BOLD, 25)); Countpanel.add(userJieguoList.get(ou)); ou++; } } CreateRandom();//调用创建随机题目的方法CreateRandom(); } public void CreateRandom(){ lianxiti.CreateRandom(); } }
package com.yu.project; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import javax.swing.AbstractButton; import javax.swing.BorderFactory; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JRadioButton; import javax.swing.JTextField; import com.yu.config.MyConfig; import com.yu.jishiqi.jishiqi; import com.yu.test.start; public class SomeListener { public int num ;//设置用户答对的题数 public JLabel CountLable; //public List<Integer> userlist = new ArrayList<>();//创建存储用户计算结果的集合 public JButton Clearbutton;//创建清空按钮 public JButton Resetbutton;//创建重置按钮 public JButton Printfbutton;//创建打印按钮 public List<Integer> userlist = new ArrayList<>(); public Count count; public SomeListener(Count count){ this.count=count; } public void myAddActionLIstener() { //为清空按钮添加动作监听 count.Clearbutton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { for(JTextField cleartextField : LableAndResult.userJieguoList){ cleartextField.setText(""); cleartextField.setBorder(BorderFactory.createLineBorder(Color.GRAY)); } } }); //为重置按钮添加动作监听 count.Resetbutton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { count.miaobiao.sec.setText(jishiqi.KONG+"00"); count.miaobiao.min.setText("00"+jishiqi.KONG); count.miaobiao.miaobiaoMan.setSuspend(true); count.miaobiao.miaobiaoMan.restart=true; new start().startlx(); System.out.println(count.miaobiao.miaobiaoMan.isAlive()); //count.miaobiao.startMiaoniao(); count.CountLable.setText(""); count.Countpanel.removeAll(); count.init(); count.le.CreateRandom(); for(JTextField cleartextField : LableAndResult.userJieguoList){ cleartextField.setText(""); cleartextField.setBorder(BorderFactory.createLineBorder(Color.GRAY)); } } }); //为秒表面板添加监听 count.miaobiaopanel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if(count.miaobiao.miaobiaoMan.isSuspend()) { count.miaobiao.miaobiaoMan.setSuspend(false); }else { count.miaobiao.miaobiaoMan.setSuspend(true); } } }); //为打印按钮添加监听 count.Printfbutton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { Integer i; Double result; num = 0; //停止秒表 //获取用户在文本框中输入的计算结果 for(i = 0;i<LableAndResult.userJieguoList.size();i++){//list为用户输入计算结果的文本框集合 //Integer.parseInt()方法用于将字符串转换成数字 if(LableAndResult.userJieguoList.get(i).getText().equals("")) { userlist.add(-1); }else { userlist.add(Integer.parseInt(LableAndResult.userJieguoList.get(i).getText())); } } count.miaobiao.miaobiaoMan.setSuspend(false); //计算用户做对的题目个数 for(i = 0;i<userlist.size();i++){ if(userlist.get(i) == LableAndResult.trueList.get(i)){//list2为所有题目正确答案的集合 num++;//num为用户计算正确的个数 LableAndResult.userJieguoList.get(i).setBorder(BorderFactory.createLineBorder(Color.GREEN)); }else { LableAndResult.userJieguoList.get(i).setBorder(BorderFactory.createLineBorder(Color.RED)); } } //计算用户做题的正确率 result = ((num*1.0)/(LableAndResult.tiList.size())*100); count.CountLable.setText(result + "%"); userlist.clear(); } }); //设置按钮加监听 count.myradio.set.addActionListener(new ActionListener() { JButton c1 = count.myradio.set; @Override public void actionPerformed(ActionEvent arg0) { String msg=""; ButtonGroup radios=count.myradio.bg; Enumeration<AbstractButton> radioBtns=radios.getElements(); while (radioBtns.hasMoreElements()) { AbstractButton btn = radioBtns.nextElement(); if(btn.isSelected()){ msg=btn.getText(); break; } } MyConfig.myMap.put("年级", msg); MyConfig.myMap.put("题数", count.myradio.tishu.getText()); // count.myradio.tishu.getText(); // System.out.println(count.myradio.tishu.getText()); } }); } }
psp
PSP阶段 | 实际花费时间百分比 | 估计花费时间百分比 |
计划 | 10 | 8 |
明确需求和其他相关因素,估计每个阶段的时间成本 | 6 | 4 |
开发 | 84 | 86 |
需求分析 | 7 | 8 |
生成设计文档 | 4 | 8 |
设计复审(和同事审核设计文档) | 4 | 4 |
代码规范(为目前的开发制定合适的规范) | 2 | 3 |
具体设计 | 11 | 13 |
具体代码 | 31 | 30 |
代码复审 | 13 | 10 |
测试(自测,修改代码,提交修改) | 12 | 10 |
报告 | 8 | 8 |
测试报告 | 3 | 3 |
计算工作量 | 2 | 2 |
事后总结,并提出过程改进计划 | 3 | 3 |