天天看點

5四則運算系統結對

結對項目—國小生四則運算系統

 首先,感謝隊友~

一、Coding.Net項目位址:

    https://git.coding.net/laolaf/nidayeproject.git

二、PSP表格

psp 任務内容 計劃共需要的時間(min)
Planning 計劃 40
Estimate 估計時間,規劃流程 20
Development 開發 1200
Analysis 需求分析&學習技術 120
Design Spec 生成設計文檔
Design Review 設計複審
Coding Standard 代碼規範 5
Design 具體設計 30
Coding 具體編碼 800
Coding Review 代碼複審 45
Test 測試(自我測試,修改代碼,送出修改)
Reporting 報告
Test Report 測試報告
Size Measurement 計算工作量

三、接口設計

    Information Hiding (資訊隐藏)

    防止修改程式的其他部分。提供一個穩定的接口保護程式的其餘部分(最有可能改變的細節)。将所有的計算和展示子產品進行類的封裝,提高程式的安全性和穩定性。

    Interface Design(接口設計)

    子產品化設計的思想,專注于每一個類,不同的類有不同的方法,使其互相獨立,最後做統一排程,使其便于維護。

    Loose Coupling(松耦合)

    與緊耦合相對立,使程式内部不易互相錯誤影響。

四、計算子產品接口的設計和實作

   使用的類一覽

    Command.java

    Cal.java

    Arithmetic.java

    Arithmetic Test.java

    Athritic.java

    Complex.java

    English.java

    Main.java

    Timer.java

    Timu2.java

視圖如下 

5四則運算系統結對

    Command:參數抛出&提供測試 

    Create:制作題目,CreateQuestion

    Cal:實作計算功能

    GUI

    GUI Time計算時間

    GUI Judge進行判斷,對錯數目

    GUI Create

    另外,用到了按鈕監聽器和檔案監聽器

五、計算子產品接口部分的性能改進

5四則運算系統結對

六、計算子產品部分單元測試展示

5四則運算系統結對

七、計算子產品部分異常處理說明

異常處理有五種,分别對參數輸入錯誤(數字變字母),對m的輸入大小範圍有誤,m後兩個參數大小颠倒,對n的輸入n的大小範圍出問題,參數o的範圍大小有問題(應該的範圍:1到10),而這些代碼的寫法都差不多,是以就展示抛出參數錯誤的代碼。(這裡的抛出我是直接列印在黑窗上了,直接抛出可能會被當成Command本身出了問題。)

public static void parameter1Error(String ex,int i)throws Exception{
    ArrayList<String> ma= new ArrayList<String>(); 
    ma.add("-n");ma.add("-m");
    ma.add("-o");ma.add("-c");
    ma.add("-b");

if(!ma.contains(ex)){
        System.out.println("參數錯誤,重新輸入");
    }
}
      
5四則運算系統結對
5四則運算系統結對

八、界面子產品設計過程

guijudge核心代碼:通過buttton1及監聽類addActionListener完成記錄和判斷

1

2

3

4

6

7

8

9

10

11

12

13

14

15

16

17

18

19

21

22

23

24

25

26

27

JButton button_1 = 

new

JButton(

"送出答案"

);

button_1.addActionListener(

new

ActionListener() {

public

void

actionPerformed(ActionEvent e) {

String[] ans =textArea_1.getText().split(

"\n"

);

String strings[]=

new

String[list11.size()];

for

(

int

i=

,j=list11.size();i<j;i++){

strings[i]=list11.get(i);

int

count=

;

for

(

int

i = 

;i < list11.size();i++){

if

(ans[i].equals(strings[i])) 

{

print.add(

"對\n"

);

count++;

else

{print.add(

"錯\n"

);}

}

textArea_2.append(print+

"\n"

);

double

sum =((

double

)count/(

double

)(list11.size()))*

100

;

lblNewLabel.setText(

"正确率:"

+sum+

"%"

);

}

});

guicreate:

JButton btnSubmitAnswer = new JButton("Submit answer");

btnSubmitAnswer.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String[] ans =textArea_1.getText().split("\n");

String strings[]=new String[list11.size()];

for(int i=0,j=list11.size();i<j;i++){

strings[i]=list11.get(i);

} int count=0;

for(int i = 0;i < list11.size();i++){

//answer.add(ans[i]+"");}

//for(String str1:answer)  

//{  

if(ans[i].equals(strings[i])) 

{

print.add("Right\n");

count++;

}  

else{print.add("Wrong\n");}

}

//for(int i=0,j=print.size();i<j;i++){

textArea_2.append(print+"\n");

double sum =((double)count/(double)(list11.size()))*100;

lblNewLabel.setText("Accuracy:"+sum+"%");

// String [] print1=print;

//}

});

btnSubmitAnswer.setBounds(30, 236, 124, 23);

contentPane.add(btnSubmitAnswer);

getContentPane().setLayout(null);

JScrollPane scrollPane = new JScrollPane();

scrollPane.setBounds(20, 49, 146, 177);

contentPane.add(scrollPane);

scrollPane.setViewportView(textArea);

textArea.setBackground(UIManager.getColor("Button.background"));

textArea.setFont(new Font("MS Gothic", Font.PLAIN, 18));

JScrollPane scrollPane_1 = new JScrollPane();

scrollPane_1.setBounds(176, 49, 62, 177);

contentPane.add(scrollPane_1);

textArea_1.setFont(new Font("Monospaced", Font.PLAIN, 15));

scrollPane_1.setViewportView(textArea_1);

JScrollPane scrollPane_2 = new JScrollPane();

scrollPane_2.setBounds(265, 49, 62, 177);

contentPane.add(scrollPane_2);

textArea_2.setFont(new Font("Monospaced", Font.PLAIN, 18));

scrollPane_2.setViewportView(textArea_2);

textArea_2.setBackground(UIManager.getColor("Button.background"));

JButton btnCallTimer = new JButton("Call timer");

btnCallTimer.addActionListener(new ActionListener() {

new timer().setVisible(true); }

btnCallTimer.setBounds(297, 238, 127, 23);

contentPane.add(btnCallTimer);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 450, 300);

contentPane = new JPanel();

contentPane.setForeground(Color.BLACK);

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

contentPane.setLayout(null);

JLabel lblQing = new JLabel("\u8BF7\u8F93\u5165\u9898\u76EE\u6570\u91CF");

lblQing.setBounds(78, 10, 103, 35);

contentPane.add(lblQing);

textField = new JTextField();

textField.setBounds(191, 17, 66, 21);

contentPane.add(textField);

textField.setColumns(10);

  

 以及:

28

29

31

32

33

34

35

36

37

38

39

41

42

43

44

46

47

48

49

50

51

52

53

54

55

56

57

58

59

JButton btnSubmitAnswer = 

new

JButton(

"Submit answer"

);

btnSubmitAnswer.addActionListener(

new

ActionListener() {

public

void

actionPerformed(ActionEvent e) {

String[] ans =textArea_1.getText().split(

"\n"

);

String strings[]=

new

String[list11.size()];

for

(

int

i=

,j=list11.size();i<j;i++){

strings[i]=list11.get(i);

}  

int

count=

;

for

(

int

i = 

;i < list11.size();i++){

//answer.add(ans[i]+"");}

//for(String str1:answer)  

//{  

if

(ans[i].equals(strings[i])) 

{

print.add(

"Right\n"

);

count++;

}                    

else

{print.add(

"Wrong\n"

);}

}

//for(int i=0,j=print.size();i<j;i++){

textArea_2.append(print+

"\n"

);

double

sum =((

double

)count/(

double

)(list11.size()))*

100

;

lblNewLabel.setText(

"Accuracy:"

+sum+

"%"

);

// String [] print1=print;

//}

}

});

btnSubmitAnswer.setBounds(

30

236

124

23

);

contentPane.add(btnSubmitAnswer);

getContentPane().setLayout(

null

);

JScrollPane scrollPane = 

new

JScrollPane();

scrollPane.setBounds(

20

49

146

177

);

contentPane.add(scrollPane);

scrollPane.setViewportView(textArea);

textArea.setBackground(UIManager.getColor(

"Button.background"

));

textArea.setFont(

new

Font(

"MS Gothic"

, Font.PLAIN, 

18

));

JScrollPane scrollPane_1 = 

new

JScrollPane();

scrollPane_1.setBounds(

176

49

62

177

);

contentPane.add(scrollPane_1);

textArea_1.setFont(

new

Font(

"Monospaced"

, Font.PLAIN, 

15

));

scrollPane_1.setViewportView(textArea_1);

JScrollPane scrollPane_2 = 

new

JScrollPane();

scrollPane_2.setBounds(

265

49

62

177

);

contentPane.add(scrollPane_2);

textArea_2.setFont(

new

Font(

"Monospaced"

, Font.PLAIN, 

18

));

scrollPane_2.setViewportView(textArea_2);

textArea_2.setBackground(UIManager.getColor(

"Button.background"

));

JButton btnCallTimer = 

new

JButton(

"Call timer"

);

btnCallTimer.addActionListener(

new

ActionListener() {

public

void

actionPerformed(ActionEvent e) {

new

timer().setVisible(

true

);           }

});

btnCallTimer.setBounds(

297

238

127

23

);

contentPane.add(btnCallTimer);

九、界面子產品與計算子產品的對接

調用Cal的cal方法,原先求值和現在通過了一次資料類型轉換。

String c = (data1+operator[i]+data2+

"="

);

textArea.append(c+

"\n"

);

String rightanswer=Cal.cal(data1,operator[i],data2);

list11.add(rightanswer);

 Cal子產品:

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

BigDecimal jieguo;

public

BigDecimal Cal(String str) {

if

(str == 

null

) {

return

null

;

}

String fuhao = 

""

;

int

index = 

;

str = str.replaceAll(

"--"

"+"

); 

// 等價替換;

str = str.replaceAll(

" "

""

); 

// 去掉空格

fuhao = 

"("

;

index = str.lastIndexOf(fuhao);

if

(index >= 

) {

int

rightIndex = str.indexOf(

")"

, index);

String left = str.substring(

, index);

String right = 

""

;

if

(rightIndex + 

1

< str.length()) {

right = str.substring(rightIndex + 

1

);

}

BigDecimal middle = Cal(str.substring(index + 

1

, rightIndex));

return

Cal(left + middle + right);

}

fuhao = 

"+"

;

index = str.lastIndexOf(fuhao);

if

(index > 

) {

BigDecimal left = Cal(str.substring(

, index));

BigDecimal right = Cal(str.substring(index + 

1

));

return

left.add(right);

}

fuhao = 

"-"

;

index = str.lastIndexOf(fuhao);

if

(index == 

) { 

// 負數處理

BigDecimal result = Cal(str.substring(index + 

1

));

if

(result.compareTo(

new

BigDecimal(

"0"

)) == -

1

) { 

// 小于0

return

result.abs(); 

// 絕對值

else

{

return

result.negate(); 

// 相反數

}

else

if

(index > 

) {

BigDecimal left = Cal(str.substring(

, index));

BigDecimal right = Cal(str.substring(index + 

1

));

return

left.subtract(right);

}

fuhao = 

"*"

;

index = str.lastIndexOf(fuhao);

if

(index > 

) {

BigDecimal left = Cal(str.substring(

, index));

BigDecimal right = Cal(str.substring(index + 

1

));

return

left.multiply(right);

}

fuhao = 

"÷"

;

index = str.lastIndexOf(fuhao);

if

(index > 

) {

BigDecimal left = Cal(str.substring(

, index));

BigDecimal right = Cal(str.substring(index + 

1

));

return

left.divide(right);

}

return

new

BigDecimal(str);

十、結對過程(照片)

5四則運算系統結對

十一、結對程式設計的優點和缺點

    結對程式設計的優點:

結對程式設計是一個特殊的開發模式,開發複審一體化的模式。

結對程式設計是個漸進的過程,度過學習階段後,開發的品質和效率大大提高。

兩人結對,可以分工合作,提高效率,減輕負擔。

    結對程式設計的缺點:

結對程式設計需要和隊友交流,需要較好的交流技巧。

考驗合作的能力,需要有學習适應的過程。

    隊友的優點和缺點

隊友coding水準還是可以的,

缺點,不是很擅長與人交流。

十二、在附錄提供的PSP表格記錄各個子產品耗時