Job 1:java arithmetic

Source: Internet
Author: User

Arithmetic topic generation Program (console based)
First, demand analysis:
1. Use the-n parameter to control the number of generated topics, using the-R parameter to control the range of values (natural number, true fraction, and true fraction denominator) in the topic
2. The number of operators in each topic does not exceed 3
3. If a false score is applied to the title and the result of the calculation, the true fractional representation
4. Put the generated topic into Exercise.txt, the answer of the question is deposited in Answer.txt, the user does the result to deposit Grade.txt
5. The program supports the generation of 10,000 topics
6. Check the generated topics
Second, the function design
According to the user requirements input parameters to generate relative to the topic, and the answer to the question.
Iii. Design and implementation


1. Generate a two-tree (Formulatree.java) of the arithmetic expression
The binary tree is constructed according to the topic requirement, and the operator is placed in the leaf node, and the non-leaf node is placed into the operators, then the two-fork tree is generated.


A recursive method is used to generate the structure of a two-fork tree, in which the number of operators is randomly determined using random numbers, Numberoperator is used to represent the total number of binary tree operators, and lnumoperator is used to represent the number of operators of the left subtree. Rnumoperator the number of operators used to represent the right subtree.
2. Read the desired expression from the two-fork tree (Show.java)
Sequential traversal of binary tree, generating relative arithmetic expression
3. Calculate the value of this expression (Calculate.java)
Post-traverse binary tree, calculate the value of the expression

4. Initializing a text file (Initfile.java)
5. Save title answers, results and scores to a text file (Inputfile.java)
6. Node Class (Node.java)

7. Generate random Number (Number.java)
8. Randomly generated relative operator (Operator.java)
9. Simplification of fractions (Simply.java)
10. Main function (Test.java)
Iv. Test Run

Vi. Summary
This program according to Mr. into storage arithmetic two fork tree, and then traverse the binary tree to generate arithmetic expression and value, due to the operation of the two fork tree is not skilled, resulting in the process of checking the weight of defects, and the output may have some problems, to be gradually improved.

Code Link: https://gitee.com/laisihong/laisihong.git

Job 1:java arithmetic

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.