天天看點

結對項目-四則運算 “軟體”之更新版

結對項目-四則運算 “軟體”之更新版

作業檔案上傳的github位址為:https://github.com/2392030179/work.git

作業要求來自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2232

結伴同學:黃健科,201606120094,http://www.cnblogs.com/huangjianke123/p/9860721.html

一、從個人項目出發,将程式改裝成一個單機帶使用者界面(不是控制台)的程式,這個程式最基本要達到:

①生成題目,單個題目最多不能超過4個運算符,操作數小于100。

②使用者可以輸入答案

③若使用者輸入答案正确,則提示正确;若答案錯誤,則提示錯誤,并要提示正确答案是多少。

二、下面附有 8 個互相獨立的可以擴充的方向。 

①程式可以出帶括号的正整數四則運算,支援分數,除法保留兩位小數,如:(1/3+1)*2 = 2.67,特别注意:這裡是2.67而非2.66,或保持分數形式:8/3

②可以出表達式裡含有負整數(負整數最小不小于-100)的題目,且負數需要帶括号,使用者輸入的結果不用帶括号。如: 2*(-4) = -8

③使用者答題結束以後,程式可以顯示使用者答題所用的時間

④使用者可以選擇出題的個數(最多不能超過5個題目),答題結束可以顯示使用者答錯的題目個數和答對的題目個數

⑤使用者在第一次答題時,需要使用者輸入使用者名,使用者下次啟動後,程式需要記住使用者前一次輸入的使用者名 

⑥程式可以出單個整數階乘的題目:如:4!=24

⑦程式可以設定答題時間,時間設定為整數,機關為秒,最大不能超過120秒,若超過了答題時間未答題,則提示:時間已到,不能答題。

⑧程式可以設定皮膚功能,可以改變界面的顔色即可。

 三、開發環境

工具:intellij  idea

語言:java

四、團隊分工

黃建科094:界面代碼編寫

黃觀國075:部分核心算法代碼書寫

五、運作情況

①輸入錯誤答案時:

結對項目-四則運算 “軟體”之更新版

②輸入答案正确時:

結對項目-四則運算 “軟體”之更新版

 六、實驗總結

首先呢,在這次的實驗任務中,我組完成了實驗的基本需求,也就是建造一個有可視界面的四則運算練習器,其中的無論時設計或編寫界面代碼,核心算法代碼時,我們都碰到了不少的問題(這裡就不贅述了),也獲得了不少經驗。

但事實上,由于時間的關系我們本來的實驗計劃并不能完整實施,就比如我組原計劃在拓展功能上選擇:

四個拓展功能加以實作的,但直到部落格釋出之前我組隻完成了基本的需求,⑧号功能已經接近解決,而其他的三個功能也有了初步的眉目,是以在拓展功能實作方面,我組表示遺憾,望諒解。

核心代碼展示

public  int question(){

        Random random=new Random();
        int ramNumber1=(int) (Math.random()*100);
        int ramNumber2=(int) (Math.random()*100);
        int ramNumber3=(int) (Math.random()*100);
        String[] operator={"+","-","*","/"};
        int operatorIndex1=(int) (Math.random()*4);
        int operatorIndex2=(int) (Math.random()*4);
        int resultFirst=0;
        if (operatorIndex1<operatorIndex2){
            resultFirst= arithmetic(ramNumber2,ramNumber3,operator[operatorIndex2]);
            resultLast= arithmetic(ramNumber1,resultFirst,operator[operatorIndex1]);
        }
        else {
            resultFirst= arithmetic(ramNumber1,ramNumber2,operator[operatorIndex1]);
            resultLast= arithmetic(resultFirst,ramNumber3,operator[operatorIndex2]);
        }

       // System.out.println(ramNumber1+operator[operatorIndex1]+ramNumber2+operator[operatorIndex2]+ramNumber3+"=");

        question=Integer.toString(ramNumber1)+operator[operatorIndex1]+Integer.toString(ramNumber2)
                +operator[operatorIndex2]+Integer.toString(ramNumber3)+"=";

        return resultLast;
    }      

界面代碼展示

public void mainFram(){
        Container container=getContentPane();
        setLayout(null);
        setBounds(100,100,1200,700);


        JButton setQuestion=new JButton("出題");
        setQuestion.setFocusPainted(false);
        setQuestion.setBounds(350,310,100,50);
        setQuestion.setFont(new Font("宋體",Font.BOLD,20));

        JButton submitAnswer=new JButton("送出");
        submitAnswer.setFocusPainted(false);
        submitAnswer.setBounds(750,310,100,50);
        submitAnswer.setFont(new Font("宋體",Font.BOLD,20));

        JTextField question=new JTextField();
        question.setFont(new Font("宋體",Font.BOLD,50));
        question.setBounds(350,0,500,250);

        JTextField answer=new JTextField();
        answer.setFont(new Font("宋體",Font.BOLD,50));
        answer.setBounds(350,260,500,50);

        JLabel jLabel=new JLabel("答題區:");
        jLabel.setFont(new Font("宋體",Font.BOLD,50));
        jLabel.setBounds(170,260,500,50);

        container.add(setQuestion);
        container.add(submitAnswer);
        container.add(question);
        container.add(answer);
        container.add(jLabel);
        setVisible(true);


        ariOperation=new AriOperation();
        result=ariOperation.question();
        question.setText(ariOperation.question);

        submitAnswer.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String judge1="回答正确";
                String judge2="回答錯誤,正确答案是:"+Integer.toString(result);


                if (Integer.parseInt(answer.getText()) == result)
                    new Judge(judge1).setVisible(true);
                else
                    new Judge(judge2).setVisible(true);
            }
        });

        setQuestion.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ariOperation=new AriOperation();
                result=ariOperation.question();
                question.setText(ariOperation.question);
            }
        });


    }
}      

七、結對軟體過程耗時估計與統計表

PSP2.1 Personal Software Process Stages Time Senior Student(h) Time(h)
Planning 計劃 3
· Estimate 估計這個任務需要多少時間 8 18
Development 開發 10 12
· Analysis 需求分析 (包括學習新技術) 2
· Design Spec 生成設計文檔 1
· Design Review 設計複審
· Coding Standard 代碼規範
· Design 具體設計 4 5
· Coding 具體編碼 16
· Code Review 代碼複審
· Test 測試(自我測試,修改代碼,送出修改)
Reporting 報告
· 測試報告
計算工作量
并提出過程改進計劃