Topic:
- Please write a "software" that can automatically generate primary arithmetic topics.
- Allow the program to accept the user to enter the answer, and determine the right and wrong.
- Finally, the total number of pairs/errors is given.
A: Basic requirements
1: Select the interface design, select Add, subtract, multiply, divide the operation.
2: The system randomly generates two numbers within 100.
3: During the exercise, the user input results from the keyboard, correct and error are prompted, press 6, display the total number of questions and correct number.
Second: Demand analysis
The preparation of primary school arithmetic test system, requires the completion of two-digit addition, subtraction, multiplication, in addition to arithmetic. Can be based on user input to choose the type of operation, the user input answers can be judged correct, after a test, the user can decide whether to continue the next operation.
Three: Design
1: Define variable i,j,a,b,m where I is the correct number of questions, J indicates the number of answers to the wrong question, a, b indicates the number randomly generated, and m receives the result of the operation from the keyboard input.
2: Define add, subtract, multiply, divide the sub function, error and correct all have hints respectively.
3: The main use of Java language to implement user input to select the type of operation, and output the number of questions and correct number of questions.
Four: Code implementation (JAVA)
1 ImportJava.text.DecimalFormat;2 ImportJava.util.Scanner;3 Public classZQ { Public Static voidMain (string[] args)4{String condition = ""; ZQ Zhidao =NewZQ (); 5 Do{Scanner Scanner =NewScanner (system.in); 6 Try{System.out.print ("Please enter the first number:"); 7 Doublex =scanner.nextdouble (); 8System.out.print ("Please enter a second number:"); 9 Doubley =scanner.nextdouble (); TenSystem.out.print ("Please enter operator:"); OneString s =Scanner.next (); A Charz = S.charat (0); - Zhidao.yunsuan (x, y, z); } - Catch(Exception e) {System.out.println ("Please enter the correct data! "); } theSystem.out.print ("Do you want to continue?" Continue: Continue, any character: End "); Condition =Scanner.next (); } - while("Continue". Equals (condition)); } - Public Static voidYunsuan (DoubleXDoubley,character z) -{DecimalFormat r=NewDecimalFormat (); R.applypattern ("#0.00");if(Z.equals (' + '))) +{System.out.println (x+ "+" +y+ "=" + R.format ((x+y))); }Else if(Z.equals ('-'))) -{System.out.println (x+ "-" +y+ "=" + R.format (x-y)); }Else if(Z.equals (' * '))) +{SYSTEM.OUT.PRINTLN (x+ "*" +y+ "=" + R.format ((x*y))); }Else if(Z.equals ('/'))) A{if(y==0) {System.out.println ("dividend cannot be 0"); } at Else{System.out.println (x+ "/" +y+ "=" + R.format (x/( y))); } } - Else{System.out.println ("Change operator not recognized"); } } -}
V: System Testing
VI: PSP time-consuming statistics
VII: Post-mortem analysis and summary
C is a freshman, Java is a junior school semester, may be more familiar with the Java language writing, so I choose to write in the Java language. With this experiment, although the process is very difficult to meet a lot of difficulties, but when the results come out very happy, very fulfilling. Look after a lot of refueling.
Second assignment: Write a arithmetic "software"