Third time job

Source: Internet
Author: User
Tags mul

Package Csniu;

Import Java.util.Random;
Import Java.util.Scanner;

public class Calculate
{
randomrandom= new Random ();
scannerscanner= new Scanner (system.in);
Intx, Y, answer, right, fault;

public static void Main (string[] args)
{
Calculate Calculate = new Calculate ();
Scanner Scanner = new Scanner (system.in);
System.out.print ("Please select operator. 1 Plus, 2 minus, 3 times, 4 apart. ");
int select = Scanner.nextint ();
System.out.print ("Please specify the number of items.") ");
int time = Scanner.nextint ();
Switch (SELECT)
{
Case 1:
for (int i = 0; i < time; i++)
{
Calculate.add ();
}
System.out.print ("You are against" + calculate.right + "dao, wrong" + Calculate.fault + "Tao. ");
Break
Case 2:
for (int i = 0; i < time; i++)
{
Calculate.sub ();
}
System.out.print ("You are against" + calculate.right + "dao, wrong" + Calculate.fault + "Tao. ");
Break
Case 3:
for (int i = 0; i < time; i++)
{
Calculate.mul ();
}
System.out.print ("You are against" + calculate.right + "dao, wrong" + Calculate.fault + "Tao. ");
Break
Case 4:
for (int i = 0; i < time; i++)
{
Calculate.div ();
}
System.out.print ("You are against" + calculate.right + "dao, wrong" + Calculate.fault + "Tao. ");
Break
Default
Break
}
}

void Randnumber ()
{
x = Random.nextint (11);
y = random.nextint (11);
}

void Add ()
{
Randnumber ();
System.out.println ("Please enter" + x + "+" + y + "The correct answer:");
while (true)
{

Try
{
Scanner Scanner = new Scanner (system.in);
Answer = Scanner.nextint ();
Break
}
catch (Exception e)
{
System.out.println ("Please enter an integer. ");
}
}
if (Answer! = (x + y))
{
fault++;
}
Else
{
right++;
}
}

void Sub ()
{
Randnumber ();
if (x < y)
{
System.out.print ("Please enter" + y + "-" + x + "The correct answer:");
Answer = Scanner.nextint ();
if (answer! = (y-x))
{
fault++;
}
Else
{
right++;
}
}
System.out.println ("Please enter" + x + "-" + y + "The correct answer:");
while (true)
{

Try
{
Scanner Scanner = new Scanner (system.in);
Answer = Scanner.nextint ();
Break
}
catch (Exception e)
{
System.out.println ("Please enter an integer. ");
}
}
if (Answer! = (x-y))
{
fault++;
}
Else
{
right++;
}
}

void Mul ()
{
Randnumber ();
System.out.println ("Please enter" + x + "*" + y + "The correct answer:");
while (true)
{

Try
{
Scanner Scanner = new Scanner (system.in);
Answer = Scanner.nextint ();
Break
}
catch (Exception e)
{
System.out.println ("Please enter an integer. ");
}
}
if (Answer! = (x * y))
{
fault++;
}
Else
{
right++;
}
}

void Div ()
{

Randnumber ();
if (x==0)
{
System.out.print ("Please enter" + y + "/" + x + "for the correct answer:");
Answer = Scanner.nextint ();
if (answer! = (y/x))
{
fault++;
}
Else
{
right++;
}
}
System.out.println ("Please enter" + x + "/" + y + "for the correct answer:");
while (true)
{

Try
{
Scanner Scanner = new Scanner (system.in);
Answer = Scanner.nextint ();
Break
}
catch (Exception e)
{
System.out.println ("Please enter an integer. ");
}
}
if (Answer! = (x/y))
{
fault++;
}
Else
{
right++;
}
}
}1: Judging user input
14:16:43
2:
14:16:59
Subtraction does not allow negative results
14:17:15
3: Division does not allow the divisor to be 0 My pair programming object is Wang He summary: Through this work, so that we understand each other's ideas deepen our friendship can also help each other, teach each other, can get the ability to complement each other. In programming, talking to each other can solve problems faster and more efficiently.

Third time job

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.