Package Csniu;
Import Java.util.Random;
Import Java.util.Scanner;
public class Calculate
{
Static randomrandom= new Random ();
scannerscanner= new Scanner (system.in);
Intx, y;
Static intanswer;
Static intright;
Static Intfault;
static int time;
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.") ");
Time = Scanner.nextint ();
System.out.print ("is the blending operation.) 0: Yes. 1: No ");
int g = Scanner.nextint ();
if (g = = 0)
{
Hunhe ();
}
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++;
}
}
public static void Hunhe ()
{
Scanner Scanner = new Scanner (system.in);
int x;
int y;
int z;
int s = random.nextint (4);
for (int i = 0; i < time; i++)
{
x = Random.nextint (11);
y = random.nextint (11);
z = random.nextint (11);
Switch (s)
{
Case 0:
System.out.println ("Please enter" + x + "+" + "(" + y + "*" + z + ")" + "result;");
Answer = Scanner.nextint ();
if (answer! = x + (Y * z))
{
fault++;
}
Else
{
right++;
}
Break
Case 1:
if (y = = 0)
{
System.out.println ("Please enter" + x + "+" + "(" + z + "/" + y + ")" + "result;");
Answer = Scanner.nextint ();
if (answer! = x + (z/y))
{
fault++;
}
Else
{
right++;
}
Break
}
System.out.println ("Please enter" + x + "+" + "(" + y + "/" + z + ")" + "result;");
Answer = Scanner.nextint ();
if (answer! = x + (y/z))
{
fault++;
}
Else
{
right++;
}
Break
Case 2:
if (x < (Y * z))
{
System.out.println ("Please enter" + "(" + y + "*" + z + ")" + "-" + x + "result;");
Answer = Scanner.nextint ();
if (answer! = (Y * z)-X)
{
fault++;
}
Else
{right++;
}
Break
}
System.out.println ("Please enter" + x + "-" + "(" + y + "*" + z + ")" + "result;");
Answer = Scanner.nextint ();
if (Answer! = x-(Y * z))
{
fault++;
}
Else
{
right++;
}
Break
Case 3:
if (y = = 0)
{
System.out.println ("Please enter" + x + "-" + "(" + z + "/" + y + ")" + "result;");
Answer = Scanner.nextint ();
if (answer! = x + (z/y))
{
fault++;
}
Else
{
right++;
Break
}
System.out.println ("Please enter" + x + "-" + "(" + y + "/" + z + ")" + "result;");
Answer = Scanner.nextint ();
if (Answer! = X-(y/z))
{
fault++;
}
Else
{
right++;
}
}
}
}
}
}
My pair programming object is Wang he!
Fourth time assignment