结对作业
项目地址:https://git.coding.net/ranko/jiedui.git
1)psp表格:
PSP2.1 |
任务内容 |
计划共完成需要的时间(min) |
实际完成需要的时间(min) |
|
Planning |
计划 |
90 |
120 |
|
· Estimate |
· 估计这个任务需要多少时间,并规划大致工作步骤(二人会议) |
90 |
120 |
|
Development |
开发 |
2920 |
3910 |
|
· Analysis |
· 需求分析 (包括学习新技术) |
30 |
120 |
|
· Design Review |
· 设计复审 |
30 |
30 |
|
· Design |
· 具体设计 |
150 |
210 |
|
· Coding |
· 具体编码 |
2500 |
3190 |
|
· Code Review |
· 代码复审 |
90 |
120 |
|
· Test |
· 测试(自我测试,修改代码,提交修改) |
120 |
240 |
|
Reporting |
报告 |
155 |
17 |
|
· Test Report |
· 测试报告 |
60 |
60 |
|
· Size Measurement |
· 计算工作量 |
5 |
5 |
|
· Postmortem & Process Improvement Plan |
· 事后总结, 并提出过程改进计划 |
30 |
30 |
|
· Blog |
· 博客撰写 |
60 |
80 |
private static final int DEFAULT_WIDTH=500; private static final int DEFAULT_HEIGHT=600; private static JLabel l1 = new JLabel(); private static long timetime;
3计算模块接口的设计与实现过程
ShowGridLayout类:生成出题页面
frame类:根据需求生成算式,并进行结果正误判断
Statistics类:进行正确题数统计
方法设计:
ShowGridLayout类:
输入题目要求,跳转到frame类生成题目:
JOptionPane.showMessageDialog(null, "欢迎使用!"); f.dispose(); //new SimpleFrame0(); SimpleFrame0 frame = new SimpleFrame0(n); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);
frame类:
生成题目:
int i=0; Random r= new Random(); String[] operate=new String[]{"+","-","*","/"}; String[] operate1=new String[]{"+","-","*"}; ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine se = manager.getEngineByName("js"); ArrayList<String> Expression=new ArrayList<String>(); ArrayList<String> Expressions=new ArrayList<String>(); for(i=0;i<n;i++) { int a=(int)(Math.random()*100); int b=(int)(Math.random()*100); int c=(int)(Math.random()*100); int d=(int)(Math.random()*100); String cz=operate[r.nextInt(4)]; String cz1=operate1[r.nextInt(3)]; String cz2=operate1[r.nextInt(3)]; String as=new String(); int s= (int)(Math.random()*3);
判断正误:
if( Expressions.get(0).equals(answers.get(0)) ){
answer1.setText("正确 "); sum++;
} else answer1.setText("错误");
计时:
class shishi3 extends Thread { private long noww = 0l; private long start = System.currentTimeMillis();// 程序启动时间的毫秒值 private long time; public void run() { int i=0; while (true) { noww = System.currentTimeMillis();// 获取一秒之后的毫秒值 time = noww - start;// 两个时间相减的到毫秒差 timetime=time; String ssss=String.format("%02d:%02d:%02d\n", time / (1000 * 60 * 60) % 60/* 时 */, time / (1000 * 60)% 60/* 分 */, (time / 1000 % 60)/* 秒 */);// 格式化字符串输出 l1.setText(ssss); i++; try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } }
跳转至Statistic统计:
public void actionPerformed(ActionEvent event) { setVisible(false); Statistics frame = new Statistics(num); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
Statistic类:
public void paint(Graphics g) { int snum2 = Integer.parseInt(snum[0]); File file = new File("result.txt"); StringBuilder result = new StringBuilder(); try { BufferedReader br = new BufferedReader(new FileReader(file));//构造一个BufferedReader类来读取文件 String s = new String(); do {//使用readLine方法,一次读一行 for(int i=0;i<4;i++) { s = br.readLine() ; save[i] = Integer.parseInt(s); } }while((s = br.readLine())!=null); br.close();
计算模块部分单元测试展示。将单元测试得到的测试覆盖率截图
计算模块部分异常处理说明。
生成答案时的异常:
String answer = new String(); try { answer=""+se.eval(w); Expressions.add(answer); } catch (ScriptException e) { // TODO Auto-generated catch block e.printStackTrace(); }
正误判断的异常:
try { File f = new File("result.txt"); FileWriter fw = new FileWriter(f,true); PrintWriter pw = new PrintWriter(fw); //pw.println(" 201571030126"); //pw.println(); for(String con:num) { pw.println(con); } fw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
计算时间的异常:
try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); }
界面模块的详细设计过程。
首先是开始页面:
public Start() { JPanel north = new JPanel(); JPanel south = new JPanel(); JLabel label = new JLabel("开始答题了,准备好了吗?",JLabel.CENTER); label.setForeground(Color.RED); JButton btn1 = new JButton("开始"); JButton btn2 = new JButton("取消"); btn1.setForeground(Color.RED); btn2.setForeground(Color.RED); add(label); south.add(btn1); south.add(btn2); add(south,BorderLayout.SOUTH); btn1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { setVisible(false); new ShowGridLayout(); //SimpleFrame0 frame = new SimpleFrame0(); //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //frame.setVisible(true); } }); btn2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("小学生四则运算系统"); setLocation(500,200); } }
这是出题界面:
public ShowGridLayout() { JFrame f=new JFrame(); f.setTitle("小学生四则运算答题系统"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setExtendedState(JFrame.MAXIMIZED_BOTH); f.setVisible(true); //设置窗口的大小和位置 f.setSize(500,350); f.setLocation(200,200); //Container con=f.getContentPane();//生成一个容器 JPanel pan1 =new JPanel(); JPanel pan2 = new JPanel(); //生成一个新的版 JPanel pan3 = new JPanel(); JPanel pan4 = new JPanel(); JPanel pan5 = new JPanel(); JPanel pan6 = new JPanel(); JPanel pan7 = new JPanel(); JPanel pan8 = new JPanel(); pan3.setBackground(Color.YELLOW); pan4.setBackground(Color.YELLOW); pan5.setBackground(Color.YELLOW); pan6.setBackground(Color.YELLOW); pan7.setBackground(Color.YELLOW); pan8.setBackground(Color.YELLOW); f.add(pan3); f.add(pan4); f.add(pan5); f.add(pan6); f.add(pan7); f.add(pan8); JLabel num=new JLabel("输入题数:"); pan3.add(num); TextField tf_num=new TextField(20); pan3.add(tf_num); JLabel low = new JLabel("题目下界:"); pan4.add(low); TextField tf_low=new TextField(20); pan4.add(tf_low); JLabel up=new JLabel("题目上界:"); pan5.add(up); TextField tf_up=new TextField(20); pan5.add(tf_up); JLabel op = new JLabel("运算符数: "); pan6.add(op); TextField tf_op=new TextField(20); pan6.add(tf_op); JLabel mul=new JLabel("乘除运算:"); pan7.add(mul); TextField tf_mul=new TextField(20); pan7.add(tf_mul); JLabel bak = new JLabel("括号运算: "); pan8.add(bak); TextField tf_bak=new TextField(20); pan8.add(tf_bak); boolean flag = true; f.add(pan1); f.setLayout(new GridLayout(8,0)); JButton b_enter=new JButton("进入"); b_enter.setForeground(Color.RED); b_enter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String myNum=tf_num.getText(); int n = Integer.parseInt(myNum); String myLow=tf_low.getText(); int ml = Integer.parseInt(myLow); String myUp=tf_up.getText(); int mu = Integer.parseInt(myUp); String myOp=tf_op.getText(); int o = Integer.parseInt(myOp); String myMul=tf_mul.getText(); //int c = Integer.parseInt(myNum); String myBak=tf_bak.getText(); //int b = Integer.parseInt(myNum); if((n>0&& n<10001) && (ml>0&& ml<1000) && (mu>10&&mu<1001) && (o>0&&o<101) && ( myMul.equals("0")|| myMul.equals("1") )&& ( myBak.equals("0")|| myBak.equals("1") ) ){ JOptionPane.showMessageDialog(null, "欢迎使用!"); f.dispose(); //new SimpleFrame0(); SimpleFrame0 frame = new SimpleFrame0(n); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } else{ JOptionPane.showMessageDialog(null, "你输入的数据有错!"); tf_num.setText( ""); tf_low.setText( ""); tf_up.setText( ""); tf_op.setText( ""); tf_mul.setText( ""); tf_bak.setText( ""); } } }); pan1.add(b_enter); JButton b_exit=new JButton("退出"); b_exit.setForeground(Color.RED); b_exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub JOptionPane.showMessageDialog(null, "谢谢使用!"); //f.setVisible(false);//隐藏窗体 System.exit(0);//退出程序 } }); pan1.add(b_exit); } }
做题页面:
JPanel northPanel1 = new JPanel(); northPanel1.setLayout(new GridLayout(1,3)); add(northPanel1,BorderLayout.NORTH); northPanel1.add(new JLabel("运算式:",SwingConstants.CENTER)); northPanel1.add(new JLabel("请输入答案:",SwingConstants.CENTER)); northPanel1.add(new JLabel("判断",SwingConstants.CENTER)); northPanel1 .setBackground(Color.pink); JPanel northPanel2 = new JPanel(); northPanel2.setLayout(new GridLayout(20,1)); northPanel2.add(rater1); northPanel2.add(answer1); northPanel2.add(rater2); northPanel2.add(answer2); northPanel2.add(rater3); northPanel2.add(answer3); northPanel2.add(rater4); northPanel2.add(answer4); northPanel2.add(rater5); northPanel2.add(answer5); northPanel2.add(rater6); northPanel2.add(answer6); northPanel2.add(rater7); northPanel2.add(answer7); northPanel2.add(rater8); northPanel2.add(answer8); northPanel2.add(rater9); northPanel2.add(answer9); northPanel2.add(rater10); northPanel2.add(answer10); northPanel2.add(rater11); northPanel2.add(answer11); northPanel2.add(rater12); northPanel2.add(answer12); northPanel2.add(rater13); northPanel2.add(answer13); northPanel2.add(rater14); northPanel2.add(answer14); northPanel2.add(rater15); northPanel2.add(answer15); northPanel2.add(rater16); northPanel2.add(answer16); northPanel2.add(rater17); northPanel2.add(answer17); northPanel2.add(rater18); northPanel2.add(answer18); northPanel2.add(rater19); northPanel2.add(answer19); northPanel2.add(rater20); northPanel2.add(answer20); rater1.setBackground(Color.YELLOW); rater3.setBackground(Color.YELLOW); rater5.setBackground(Color.YELLOW); rater7.setBackground(Color.YELLOW); rater9.setBackground(Color.YELLOW); rater11.setBackground(Color.YELLOW); rater13.setBackground(Color.YELLOW); rater15.setBackground(Color.YELLOW); rater17.setBackground(Color.YELLOW); rater19.setBackground(Color.YELLOW); answer1.setBackground(Color.YELLOW); answer3.setBackground(Color.YELLOW); answer5.setBackground(Color.YELLOW); answer7.setBackground(Color.YELLOW); answer9.setBackground(Color.YELLOW); answer11.setBackground(Color.YELLOW); answer13.setBackground(Color.YELLOW); answer15.setBackground(Color.YELLOW); answer17.setBackground(Color.YELLOW); answer19.setBackground(Color.YELLOW); add(northPanel2,BorderLayout.CENTER); final JTextArea textArea = new JTextArea(20,13); textArea.setFont(new Font(" ",Font.PLAIN,17)); add(textArea,BorderLayout.WEST); JPanel southPanel = new JPanel(); add(southPanel,BorderLayout.SOUTH); JButton insertButton = new JButton("确认"); southPanel.add(insertButton); insertButton.setForeground(Color.RED); JButton sortButton = new JButton("统计"); southPanel.add(sortButton); sortButton.setForeground(Color.RED); southPanel.add(l1); l1.setFont(new Font("",1,18));
界面模块与计算模块的对接。
界面模块与计算模块的对接是通过监听器来实现的,监听器是通过对不同按钮的点击事件进行监听,调用不同的函数方法。通过进入按钮,触发监听器,调用出题函数,并在新的页面内生成随机运算式。如下图