20165303 2017-2018-2 "Java programming" pair programming exercises _ arithmetic

Source: Internet
Author: User
Tags arithmetic

    • Demand analysis
      Can generate simple arithmetic questions and judge the user to answer right and wrong.
      Be able to correctly statistic the probability of answering the correct.
      The problem of correctly handling the priority of mixed arithmetic.
      Can correctly output negative numbers and other results.
      Can handle simple addition, subtraction, multiplication, and subtraction.
      Can correctly handle the case of parentheses and output the correct operation results, can correctly handle the situation of input anomalies.
    • Run

  • Code implementation
    Import Java.util.;
    public class Sizeyunsuan {
    public static void Main (string[] args) {
    System.out.println ("Number of input test questions:");
    Scanner sc=new Scanner (system.in);
    int Number=sc.nextint ();
    Double right = 0;
    Double wrong = 0;
    for (int i = 0; i < number; i++) {
    System.out.println ("the" + (i+1) + "question, please enter the answer below:");
    Double op1= (int) (Math.random ()
    10);
    Double op2= (int) (Math.random ()10);
    Random r3 = new Random ();
    int m = R3.nextint (4);
    Char[] CHS = {' + ', '-', '
    ‘,‘/‘};
    String Operator = string.valueof (Chs[m]);
    Generate topics
    if (operator.equals ("+")) {
    System.out.println (op1+ "+" +op2+ "=");
    Boolean B = Add (OP1,OP2);
    if (b = = true) {
    right++; System.out.println ("right!");
    }
    else{
    wrong++; System.out.println ("no");
    System.out.println ("Right Answer:" + (OP1+OP2));
    }
    }
    else if (operator.equals ("-")) {
    System.out.println (op1+ "-" +op2+ "=");
    Boolean b =minus (OP1,OP2);
    if (b = = true) {
    right++; System.out.println ("right!");
    }
    else{
    wrong++; System.out.println ("no");
    System.out.println ("Right Answer:" + (OP1-OP2));
    }
    }
    else if (Operator.equals ("")) {
    System.out.println (op1+ "x" +op2+ "=");
    Boolean b =times (OP1,OP2);
    if (b = = true) {
    right++; System.out.println ("right!");
    }
    else{
    wrong++; System.out.println ("no");
    System.out.println ("Right Answer:" + (OP1
    OP2));
    }
    }
    else{
    System.out.println (op1+ "÷" +op2+ "=");
    Boolean b =div (OP1,OP2);
    if (b = = true) {
    right++; System.out.println ("right!");
    }else{
    wrong++; System.out.println ("no");
    System.out.println ("Right answer:" +OP1/OP2);
    }
    }
    }
    System.out.println ("Did the right" +right+ "problem.");
    System.out.println ("Do Wrong" +wrong+ "the problem.");
    SYSTEM.OUT.PRINTLN ("Correct rate for" + (right/(wrong+right))100+ "%");
    }
    Private static Boolean add (double x,double y) {
    Scanner sc = new Scanner (system.in);
    Double num1 = sc.nextdouble ();
    Double result = x + y;
    if (NUM1 = = result) {
    return true;
    }else{
    return false;
    }
    }
    private static Boolean minus (double x,double y) {
    Scanner sc = new Scanner (system.in);
    Double num1 = sc.nextdouble ();
    Double result = x-y;
    if (NUM1 = = result) {
    return true;
    }else{
    return false;
    }
    }
    Private static Boolean times (double x,double y) {
    Scanner sc = new Scanner (system.in);
    Double num1 = sc.nextdouble ();
    Double result = x
    Y
    if (NUM1 = = result) {
    return true;
    }else{
    return false;
    }
    }
    private static Boolean Div (double x,double y) {
    Scanner sc = new Scanner (system.in);
    Double num1 = sc.nextdouble ();
    Double result =x/y;
    if (NUM1 = = result) {
    return true;
    }else{
    return false;
    }
    }
    }

  • WhiteStar Operation diagram
  • Code Cloud Link
    Https://gitee.com/BESTI-IS-JAVA-2018/20165303WeiYujava/tree/master/src

  • Knot to feel
    Through this week's constant revision of the code, and the small partners, and finally modified the basic implementation of the Code, and then the implementation of the function, but in the process of running there are still some bugs, not too perfect, due to time constraints, this week's experiments more, and then achieve a relatively rough, I will continue to implement this code in the course of future learning.

20165303 2017-2018-2 "Java programming" pair programming exercises _ 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.