第三次作业 结对编程1模块化

                                   201421122079 林仙平   201421122076 陈俊达

                                                            结对编程1-模块化    2017-10-21

  这次作业我和俊达选择用我的第一次作业来当源代码原因主要是我的程序是用java开发的,而俊达的是用c,而我不大会c语言,并且我们两个对java都还是比较熟悉的。

需求分析:

     在上次基础上的需求

      1、程序做成GUI

      2、记录用户的对错总数,程序退出再启动的时候,能把以前的对错数量保存并在此基础上增量计算。在结束测试时候展示历史对错题数,历史记录存放在文件中是最合理

的选择,直接读取文件就可以获取历史总对错题数,在作完一次测试后,从文件中读取历史总对错题数加上本次的对错题数后再重新写入记录文件Record.txt.

      3、有计时功能,能显示用户开始答题后的消耗时间。在开始时候记录时间,结束时候记录时间,相减实现计时,在结束测试时展示答题所用时间

      4、界面支持中文简体/英语,用户可以选择一种;选择对应语言后,把控件的显示text改成对应的语言,这样在用户的GUI界面上显示的所有语言就是用户选择的中文或者英语。

总思维导图:

                

 

显示历史总对错题数思维导图:

 

                 

代码规范:

           

 

项目截图 :

                   

代码展示:

     主函数:  public static void main(String[] args) {

                GUIcalculator GUI = new GUIcalculator();

                GUI.setVisible(true);

         }

   GUI函数://主窗口

  public class GUIcalculator extends JFrame implements ActionListener {

         int language;// 记录选择的语言

         JTextArea quesNumJTA = new JTextArea(1, 10);

         JTextArea answerJTA = new JTextArea(1, 10);

         JPanel panel = new JPanel();

         JPanel languageChoJP = new JPanel();

         JPanel quseNumJP = new JPanel();

         JPanel difficultyChooseJP = new JPanel();

         JPanel answerJP = new JPanel();

         JPanel nextJP = new JPanel();

         JPanel countJP = new JPanel();

         JPanel warningJP = new JPanel();

         JLabel numQuizJL = new JLabel("how many questions u want test?");

         JLabel difficultyQuizJL = new JLabel("easy or difficult?");

         JLabel showQuestionJL = new JLabel();// 放题目label

         JLabel resultJudgeJL = new JLabel();

         JLabel showCountJL = new JLabel();

         JLabel warningJL = new JLabel();

         JButton sureJB = new JButton("sure");

         JButton easyJB = new JButton("easy");

         JButton difficultJB = new JButton("difficult");

         JButton nextJB = new JButton("next");

         JButton submitJB = new JButton("submit");

         JButton reenterJB = new JButton("reenter");

         JButton chineseJB = new JButton("中文");

         JButton englishJB = new JButton("English")

 

 窗口重绘函数public void panelRepaint(JPanel a, JPanel b, JPanel c) {

                a.remove(b);

                a.add(c);

                a.revalidate();

                a.repaint();

         }

  读记录和重写记录public class FileInOut {

         public int[] getrecord() throws IOException {

                int[] arr = new int[2];

                String[] strRead = new String[3];

                File userinfo = new File("Record.txt");

                try {

                       InputStream in = new FileInputStream(userinfo);// 文件对象

                       InputStreamReader read;

                       read = new InputStreamReader(in, "GBK");// 设置读取格式

                       BufferedReader reader = new BufferedReader(read);

                       for (int i = 0; i < 3; i++) {

                              strRead[i] = reader.readLine();

                       }

                  } catch (UnsupportedEncodingException e) {

                       e.printStackTrace();

                       System.out.println("读文件入出错");

                }

                arr[0] = Integer.parseInt(strRead[1]);

                arr[1] = Integer.parseInt(strRead[2]);

                return arr;

         }

          public void recompose(int[] in) {

                try {

                       FileOutputStream out = new FileOutputStream("Record.txt");

                       OutputStreamWriter outWriter = new OutputStreamWriter(out, "GBK");

                       BufferedWriter bufWrite = new BufferedWriter(outWriter);

                       bufWrite.write("对错记录:第二行是对的题数、第三行是错的题数\r\n");

                       for (int i = 0; i < in.length; i++)

                              bufWrite.write(in[i] + "\r\n");

                       bufWrite.close();

                       outWriter.close();

                       out.close();

                } catch (Exception e) {

                       e.printStackTrace();

                       System.out.println("写入出错");

                }

        }

       产生表达式public static String CreateAtith(int r1, int leval){}

      计算表达式public static String countAnswer(String exp){}

运行截图:

              

                 

 

小组照片:

             

 

耗时估计:

      

 

 

小结:

       结对编程的好处是有更多的想法,有时候自己觉得最好的算法,结果经队友一说就发现了更好的算法,还有就是讨论过程中也可以产生一个人单独思考得不到的结果。在项目命名和确认好各自的分工后,结队编程能有效的减少代码开发的时间,特别是代码量越多、效果越明显。这次结对编程我觉得1+1刚好等于2,主要是在项目想法磨合上花费了太多时间、当然这是个小项目,如果项目稍微大一丁点,效果肯定是1+1>2的。

队友评价:

       满分10分我给8分,总体感觉是个完美的队友,优点是执行力很高,说什么时候能敲完一个模块就什么时候敲玩,缺点是写的代码不写注释,这让我在整合代码是花费了不少时间看代码和理解代码,希望以后可以在敲代码时关键地方加上注释。

代码地址:

    https://coding.net/u/lxp2017/p/coding/git/tree/master/

posted @ 2017-10-21 13:43  实习第二天  阅读(146)  评论(1编辑  收藏  举报