The second assignment of software engineering: Writing the arithmetic test software for pupils

Source: Internet
Author: User

First, title:

    • 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 number of total and right/wrong is given.

Second, the basic requirements:

    • The "Software" Selected interface design, select Add, subtract, multiply, divide the operation.
    • The system randomly generates two numbers within 100 of the operation.
    • When using the software, the user will be prompted to enter the results from the keyboard, answer the correct questions and answer the errors, and the system automatically gives the corresponding total and/or wrong numbers after the end.

Third, demand analysis:

    • The program can implement addition, subtraction, multiplication, and division within 0~100.
    • Users can enter their own answers in the Java Control window, which can determine the correct error of the user's input answers.
    • After the test, the program can give the number of questions and the number of correct/wrong questions.

Four, design:

    • The five variables are defined as: E, R, a, B, C, where E is the number of answers to the wrong, indicating that R represents the correct number of questions, a, and b represent randomly generated two integers between 0~100, respectively.
    • Use the scanner class to create multiple objects and invoke the appropriate methods for different operation types.
    • Add, subtract, multiply, and divide with a switch control statement to achieve, the entire implementation of the program is reflected in the main function.

Five, the code implementation:

1 ImportJava.util.Random;2 ImportJava.util.Scanner;3 4  Public classQQ {5      Public Static voidMain (string[] args) {6         intE = 0, r = 0;7System.out.println ("Welcome to arithmetic test software! ");8SYSTEM.OUT.PRINTLN ("Please read the question carefully before doing the question, wish you a happy test!") ");9Random R1 =NewRandom ();Ten          for(inti = 0; I < 7; i++) { One             intm, N; A             intA, B, C; -m = r1.nextint ()% 10; -n = m% 4; the  -             Switch(n) { -              Case0: -A =NewRandom (). Nextint ((int) Math.pow (10, 2)) + 1; +b =NewRandom (). Nextint ((int) Math.pow (10, 2)) + 1; -System.out.println (A + "+" + "" + B + "=?")); +Scanner x1 =NewScanner (system.in); Ac =x1.nextint (); at                 if(c! = A +b) { -e++; -SYSTEM.OUT.PRINTLN ("Answer Error!!!")); -}Else { -r++; -System.out.println ("Answer right!!")); in                 } -  to                  Break; +  -              Case1: theA =NewRandom (). Nextint ((int) Math.pow (10, 2)) + 1; *b =NewRandom (). Nextint ((int) Math.pow (10, 2)) + 1; $System.out.println (A + "-" + "" + B + "=?"));Panax NotoginsengScanner x2 =NewScanner (system.in); -c =x2.nextint (); the                 if(c! = A-b) { +e++; ASYSTEM.OUT.PRINTLN ("Answer Error!!!")); the}Else { +r++; -System.out.println ("Answer right!!")); $                 } $  -                  Break; -  the              Case2: -A =NewRandom (). Nextint ((int) Math.pow (10, 2)) + 1;Wuyib =NewRandom (). Nextint ((int) Math.pow (10, 2)) + 1; theSystem.out.println (A + "*" + "" + B + "" + "=?"); -Scanner y1 =NewScanner (system.in); Wuc =y1.nextint (); -                 if(c! = A *b) { Aboute++; $SYSTEM.OUT.PRINTLN ("Answer Error!!!")); -}Else { -r++; -System.out.println ("Answer right!!")); A                 } +  the                  Break; -  $              Case3: the                 DoubleD; theA =NewRandom (). Nextint ((int) Math.pow (10, 2)) + 1; theb =NewRandom (). Nextint ((int) Math.pow (10, 2)) + 1; the                 if(b = = 0) -b++; inSystem.out.println (A + "/" + "" + B + "" + "=?"); theScanner y2 =NewScanner (system.in); theD =y2.nextdouble (); About                 if(d! = (A/b)/1.00) { thee++; theSYSTEM.OUT.PRINTLN ("Answer Error!!!")); the}Else { +r++; -System.out.println ("Answer right!!")); the Bayi                 } the  the                  Break; -  -             } the         } theSYSTEM.OUT.PRINTLN ("The exam is over!! "); theSYSTEM.OUT.PRINTLN ("You have done it altogether:" + (r + E) + "road title, where the correct has" + R + "DAO, Wrong has" +e+ "Tao!" "); -     } the}

Six, the procedure:

Vii. PSP Time-consuming:

Summary: The teacher has just begun to decorate the homework when did not understand how the matter, and then in the second time on the machine class, the teacher again explained that I understand the meaning of the topic. Most of the relevant computer courses have been forgotten, for example, the use of switch control statements in C programs and the use of classes in Java do not remember, in the process of writing procedures are good time to access textbooks and materials, to seek the help of students and teachers to calculate the completion. The shortcomings of which also hope that the teacher pointed out, continue to work hard!

The second assignment of software engineering: Writing the arithmetic test software for pupils

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.