01:java_ Arithmetic Topic Generation Program (console based)

Source: Internet
Author: User

First, the topic requirements1. Use the-n parameter to control the number of generated topics, such asmyapp.exe-n- o Exercise.txt 10 topics will be generated. 2. Use the-r parameter to control the range of values (natural number, true fraction, and true fraction denominator) in the topic , for example Myapp.exe-r TenThe arithmetic topic will be generated within 10 (excluding 10). This parameter can be set to 1 or other natural number. This parameter must be given, otherwise the program will error and give help information. 3. If there are sub-expressions such as E1 ÷e2 in the generated topic , the result should be a true score . 4. There are no more than 3 operators in each topic. 5. The problem of one run of a program cannot be repeated, that is, no two topics can be transformed into the same topic by means of an arithmetic expression of the finite Exchange + and the X or so . For example, 23 + 45 = and 45 + 23 = are repetitive topics, 6x8 = and 8x6 = are also repetitive topics. The two topics of 2+1 and 1+2+3 are repetitive, because the + is left-associative, and 1+2+3 is equivalent to (1+2) +3, which is the total (1+2), which is (2+1). However, 1+2+3 and 3+2+1 are two non-repetitive problems, because 1+2+3 is equivalent to (1+2) +3, and 3+2+1 is equivalent to (3+2) +1, and they cannot be changed to the same subject by a finite exchange. The generated topic is stored in the Exercises.txt file under the current directory of the executing program, in the following format:1. Arithmetic Topic 12. Arithmetic Topic 2... where true scores are used in the input and output format, the true score Three-fifths is 3/5, the true fraction Two and three-eighths is 2 ' 3/8. 6. While generating the title, calculate the answer to all the questions and deposit the Answers.txt file in the current directory of the executing program, in the following format:1. Answer 12. Answer 2In particular, the operation of the true fraction is shown in the following example: 1/6 + 1/8 = 7/24. 7. The program should be able to support the generation of 10,000 topics. 8. The program supports a given topic file and answer file, determines the correct error in the answer and carries out the number of statistics , and will output all the topics repeat the topic , the input parameters are as follows: myapp.exe-e <exercisefile>.txt-a <answerfile>.txt- o Grade.txt the statistical results are output to the file Grade.txt, in the following format: Correct:5 (1, 3, 5, 7, 9)Wrong:5 (2, 4, 6, 8, ten)Repeat:2Repeatdetail:(1) 2,45+32 Repeat 3,32+45(2) 5,3+ (2+1) Repeat 7,1+2+3Explanation:correct:5----5 questions correct, correct problem number 1,3,5,7,9wrong:5-----5-word error, wrong problem number 2,4,6,8,10repeat:2 2---group title repeat(1) The first set of title number 2, the title 45+32 and Title 3 of the title repeat, the title number 3 is 32+45(2) The second group of title 5, the title of the 2+1 and title 7 of the title repeat, the title number 7 is 1+2+3Second, demand analysis

1. Meet the current market needs, convenient primary math problem calculation and automatic generation of exercises, easy to follow the test or exam needs, easy to provide the required questions and answers, reusable

2. Suitable for students to test their comprehensive ability, consolidate and strengthen Java programming ability, cultivate independent thinking ability and coded logical thinking

3. It belongs to the course scope of object-oriented programming, which helps teachers to collect students ' individual quality ability and programming ability, and under the premise of not copying and copying others ' code, to greatly strengthen teachers ' cognition to students ' comprehensive level.

4. restudying, suitable for students who have a certain period of time in school to complete independently

third, functional design

Be able to randomly generate test topics, in accordance with the requirements of the format and get the corresponding answer, check the weight function is not set, true scores and simplification function may be because the problem is not implemented nested, but the logic of the function has been written in the code, wherein the use of the greatest common divisor division method to find out, The numerator denominator is then divided by the corresponding number of conventions to obtain the simplest fraction, and finally the corresponding arithmetic.

Iv. design and implementation

1. Set the sub-function GCD, the sub-function within the independent completion of the division method, used for the final reduction of fractions to obtain the simplest fraction

2. Set the Sub function enter, the child function prompts to enter a number x, so that the program completes the X-generation cycle, the X-ray arithmetic topic

3. Using the switch code to implement the random arithmetic character function

Five, Key code description

using (int) (1+math.random () * (100-1+1)) to achieve a randomly generated 1--100 within the number, while generating an integer z for the different results of 1,2,3,4,z, respectively, represents the implementation of the Operation +,-,*,/.

Get greatest common divisor B by the method of dividing

Use greatest common divisor B to get the simplest score after simplification (this step is not completed for some reason, not yet debug where the error is found)

Vi. Running tests

Vii. Summary of Operations

Based on the unfamiliar operation, this job is not satisfactory, no more operators are given, there is no code to find the simplest fraction where the error resulted in not completing the function. The generation of the topic is relatively simple, Java code editing is not proficient in the future work should be strengthened in this area of learning, as far as possible to the previous learned things to fill back.

Github:https://gitee.com/cin233/test/tree/master


01:java_ Arithmetic Topic Generation Program (console based)

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.