Peer project-Upgrade of four arithmetic "Software"

Source: Internet
Author: User

Https://github.com/2392030179/work.git

Companion students:

Huang guoguo 201606120075 https://www.cnblogs.com/666hll1212123/p/9865982.html

1. Starting from a personal project, the program is converted into a single-Host Program with a user interface (not a console), which is basically achieved:

Generate a question. A single question can contain a maximum of four operators and the operand is less than 100.

Users can enter answers

If you enter the correct answer, the system prompts that the answer is correct. If the answer is incorrect, the system prompts that the answer is incorrect and the correct answer is displayed.

2. Eight independent and scalable directions are provided below.

  1. The program can return a four-digit positive integer operation with parentheses. It supports the score and the Division function keeps two decimal places, for example: (1/3 + 1) * 2 = 2.67. Note: Here is 2.67 rather than 2.66, or keep the score: 8/3
  2. You can obtain the question that the expression contains a negative integer (the minimum value of a negative integer is not less than-100), and the negative value must contain parentheses. The user input results do not contain parentheses. For example, 2 * (-4) =-8
  3. After a user answers a question, the program displays the time used by the user to answer the question.
  4. You can select the number of questions (up to five questions). After the answer is over, you can view the number of wrong questions and the number of correct questions.
  5. When you answer questions for the first time, you need to enter the user name. After the user starts the next time, the program needs to remember the user name entered previously.
  6. The program can produce the question of a single integer factorial: for example, 4! = 24
  7. The program can set the Answer time, the time is set to an integer, the unit is seconds, the maximum cannot exceed 120 seconds, if the answer time exceeds the Answer time did not answer, the prompt: the time has reached, cannot answer.
  8. The program can set the skin function to change the color of the interface.

 

2. Development Environment

Tool: intellij idea

Language: Java

 

Iii. Division of Labor

Huang jianke:

Interface code writing

Huang guoguo:

Core Algorithm functions

 

Iv. Running status

 

 

 

 

V. Summary

Through this experiment, I became more familiar with the interface design and realized that it was not easy to make a good interface.

 

Core code

public  int question(){        Random random=new Random();        int ramNumber1=(int) (Math.random()*100);        int ramNumber2=(int) (Math.random()*100);        int ramNumber3=(int) (Math.random()*100);        String[] operator={"+","-","*","/"};        int operatorIndex1=(int) (Math.random()*4);        int operatorIndex2=(int) (Math.random()*4);        int resultFirst=0;        if (operatorIndex1<operatorIndex2){            resultFirst= arithmetic(ramNumber2,ramNumber3,operator[operatorIndex2]);            resultLast= arithmetic(ramNumber1,resultFirst,operator[operatorIndex1]);        }        else {            resultFirst= arithmetic(ramNumber1,ramNumber2,operator[operatorIndex1]);            resultLast= arithmetic(resultFirst,ramNumber3,operator[operatorIndex2]);        }       // System.out.println(ramNumber1+operator[operatorIndex1]+ramNumber2+operator[operatorIndex2]+ramNumber3+"=");        question=Integer.toString(ramNumber1)+operator[operatorIndex1]+Integer.toString(ramNumber2)                +operator[operatorIndex2]+Integer.toString(ramNumber3)+"=";        return resultLast;    }

Interface code

Public void mainfram () {Container = getcontentpane (); setlayout (null); setbounds (100,100,120); jbutton setquestion = new jbutton ("Question"); setquestion. setfocuspainted (false); setquestion. setbounds (350,310,100, 50); setquestion. setfont (new font ("", Font. bold, 20); jbutton submitanswer = new jbutton ("Submit"); submitanswer. setfocuspainted (false); submitanswer. setbounds (750,310,100, 50); submitanswer. setfont (new font ("", Font. bold, 20); jtextfield question = new jtextfield (); question. setfont (new font ("", Font. bold, 50); question. setbounds (500,250, 0); jtextfield answer = new jtextfield (); answer. setfont (new font ("", Font. bold, 50); answer. setbounds (350,260,500, 50); jlabel = new jlabel ("Answer area:"); jlabel. setfont (new font ("", Font. bold, 50); jlabel. setbounds (170,260,500, 50); container. add (setquestion); container. add (submitanswer); container. add (question); container. add (answer); container. add (jlabel); setvisible (true); arioperation = new arioperation (); Result = arioperation. question (); question. settext (arioperation. question); submitanswer. addactionlistener (New actionlistener () {@ override public void actionreceivmed (actionevent e) {string judge1 = "correct answer"; string judge2 = "Incorrect answer, correct answer:" + integer. tostring (result); If (integer. parseint (answer. gettext () = Result) New judge (judge1 ). setvisible (true); else new judge (judge2 ). setvisible (true) ;}}); setquestion. addactionlistener (New actionlistener () {@ override public void actionreceivmed (actionevent e) {arioperation = new arioperation (); Result = arioperation. question (); question. settext (arioperation. question );}});}}

 

Peer project-Upgrade of four arithmetic "Software"

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.