I. Pairs of objects
1. Program Requirements
- (1). Automatic generation of topics
can be used independently (able to write the function of the test class to create a separate problem)
can generate different levels of topics, similar to:
Level 1 Topics: 2 + 5 =, 10-5 = Two numbers, the title of an operator
(2). Problem calculation (question)
Can be used independently, to achieve the infix expression to the suffix expression and calculation; Determine the user's answer right and wrong, and output the correct results
- (3). True score Support
Can be used independently to achieve the calculation of fractional formulas
- (4). Expansion requirements: topic to go heavy
Can be used independently, to achieve the de-weight of the auto-generated expression: The following if generated: 2 + 5 = & 5 + 2 = for the same topic
2. Design Analysis
- 1. Automatic generation of the topic: the difficulty of the topic here I was defined by the number of operators, according to the operator and then produce the Operation Fugai number (here is not the case of the photo fraction), and then use the loop to produce, and then output as a string.
- 2. Problem calculation (question):
First, the resulting expression is converted to a suffix expression: by writing a method, if the operand is put into the stack, if the operator is judged: the operator of the addition and subtraction encountered the top of the stack operator is multiplication or add minus, then the output stack top operator, press the plus and minus one level of the operator Multiplication first-level operator encountered a stack top operator is multiplication, the stack top operator out of the stack, pressed into the stack of operators, encountered the addition and subtraction of the operator directly into the stack.
Calculate suffix expression: Write a method: Scan the suffix expression from left to right, encounter the operand into the stack, encounter the operator will pop up the top of the stack of two elements, the results are calculated and then pressed into the stack, the last one of the remaining elements in the stack is the final answer
- 3. Support true score: not completed
3. Designing UML Class diagrams
4. Problems encountered and Solutions 5. Code display
Part I: Generating topics
import java.util.Stack;import java.util.Random;import java.util.ArrayList;import java.util.Scanner;class Questions { ArrayList<Object> array = new ArrayList<Object>(); Random generator = new Random(); char[] newchar = {'+', '-', '*', '/'}; protected int number; int NUM; public Questions() { number = 0; } public Object getQuestion(int num) { int num1 = num; while (num > 0) { int figure = (int) generator.nextInt(9) + 1; array.add(figure); number = (int) (Math.random() * 4); array.add(newchar[number]); num--; } String obj = ""; while (num < 2 * num1) { obj += array.get(num); num++; } int other = (int) generator.nextInt(9) + 1; array.add(other); obj += other + "="; return obj; }}
Part II: Topic arithmetic
Generate suffix expression public class calculations {public static void main (string[] args) {Questions questions=new Questions ( ); Stack stack = new stack (); Scanner scan=new Scanner (system.in); char c; int count=0,answer; char[] operation = new CHAR[100]; String str = (string) questions.getquestion (3); SYSTEM.OUT.PRINTLN ("Please answer the following questions: \ n" +str); System.out.println ("Please enter your answer:"); Answer=scan.nextint (); for (int i = 0; i < str.length (); i++) {c = Str.charat (i); if (c >= ' 0 ' && C <= ' 9 ') {operation[i] = C; count++; } else {if (c = = ' * ' | | c = = '/') {if (Stack.empty ()) { Stack.push ((char) c); } else if (char) stack.peek () = = ' * ' | | (char) stack.peek () = = '/') {operation[i] = (char) stack.pop (); Stack.push (c); } else Stack.push (c); } else if (c = = ' + ' | | c = = '-') {if (Stack.empty ()) {Stack.push (c); } else if (char) stack.peek () = = ' + ' | | (char) stack.peek () = = '-') {operation[i] = (char) stack.pop (); Stack.push (c); } else {Operation[i] = (char) stack.pop (); Stack.push (c); }} else Stack.push (c); }} int num = Stack.size (); for (int a = 0; a < num; a++) {operation[str.length () + A] = (char) stack.pop (); }
Suffix expression calculation stack<integer> stack1 = new stack<integer> (); int m, n, Sum,num1=str.length () + (Str.length ()-count); for (int b = 0; b <= num1; b++) {if (operation[b] >= ' 0 ' && operation[b] <= ' 9 ') stack 1.push ((int) operation[b]-48); else {if (operation[b] = = ' + ') {m = Stack1.pop (); n = Stack1.pop (); sum = n + M; Stack1.push (sum); } else if (operation[b] = = '-') {m = Stack1.pop (); n = Stack1.pop (); sum = n-m; Stack1.push (sum); } else if (operation[b] = = ' * ') {m = Stack1.pop (); n = Stack1.pop (); sum = n * m; Stack1.push (sum); } else if (operation[b] = = '/') {m = Stack1.pop (); n = Stack1.pop (); sum = n/m; Stack1.push (sum); } else if (operation[b] = = ") continue; }} if ((int) Stack1.peek () ==answer) System.out.println ("Congratulations on your answer!") "); else System.out.println ("Sorry, wrong answer!") The answer is: "+stack1.peek ());}}
Three. PSP Analysis
PSP2.1 |
Personal software Process Stages |
Estimated time-consuming (minutes) |
Planning |
Plan |
60 |
Estimate |
Estimate how long this task will take |
3 |
Development |
Development 2000 |
3000 |
Analysis |
Demand analysis (including learning new technologies) |
350 |
Coding Standard |
Code specification (to develop appropriate specifications for current development) |
60 |
Design UML |
Design Project UML class diagram |
60 |
Coding |
Specific code |
1500 |
Code Review |
Code review |
30 |
Test tests |
(Self-test, modify code, commit changes) |
300 |
Size Measurement calculation effort (actual time) |
2 |
2 |
Postmortem & Process Improvement Plan |
Summarize afterwards and propose process improvement plan |
30 |
|
Total |
4395 |
2017-2018-2 1723 "Java Programming" course pair programming Exercises _ arithmetic