课堂作业
2017-03-02 17:42 ovols 阅读(205) 评论(0) 编辑 收藏 举报import java.util.*;
class number{
private int i;
private int j;
public void seti()
{
i = 1 + (int)(Math.random() * 10);
}
public int geti()
{
return i;
}
public void setj()
{
j = 1 + (int)(Math.random() * 10);
}
public int getj()
{
return j;
}
}
class symbol{
private int a;
public void seta()
{
a = 1 + (int)(Math.random() * 4);
}
public int geta()
{
return a;
}
}
class number1{
private int i;
private int j;
private int x;
private int y;
public void setnumber()
{
i = 1 + (int)(Math.random() * 10);
j = 1 + (int)(Math.random() * 9);
x = 1 + (int)(Math.random() * 10);
y = 1 + (int)(Math.random() * 9);
}
public int getnumberi()
{
return i;
}
public int getnumberj()
{
return j;
}
public int getnumberx()
{
return x;
}
public int getnumbery()
{
return y;
}
}
public class calculate {
public static void main(String args[])
{
for(int i = 0 ; i <= 29 ; i ++){
number n1 = new number();
int a1 , a2;
n1.seti();
a1 = n1.geti();
n1.setj();
a2 = n1.getj();
symbol s = new symbol();
int b;
s.seta();
b = s.geta();
if(b == 1)
System.out.println(a1 + "+" + a2 + "=" + ( a1 + a2 ) );
if(b == 2)
System.out.println(a1 + "-" + a2 + "=" + (a1 - a2));
if(b == 3)
System.out.println(a1 + "*" + a2 + "=" + (a1 * a2));
if(b == 4)
System.out.println(a1 + "/" + a2 + "=" + a1 + "/" + a2);
}
for(int i = 0 ; i <= 29 ; i++)
{
number1 n2 = new number1();
int b1 , b2 , b3 , b4;
n2.setnumber();
b1 = n2.getnumberi();
b2 = n2.getnumberj();
b3 = n2.getnumberx();
b4 = n2.getnumbery();
symbol s1 = new symbol();
int c;
s1.seta();
c = s1.geta();
if(c == 1)
System.out.println(simplify(b2 , b1) + "+" + simplify(b4 , b3) + "=" + simplify(b2 * b4 , b1 * b3));
if(c == 2)
System.out.println(simplify(b2 , b1) + "-" + simplify(b4 , b3) + "=" + simplify(b2 * b4 , b1 * b3));
if(c == 3)
System.out.println(simplify(b2 , b1) + "*" + simplify(b4 , b3) + "=" + simplify(b2 * b4 , b1 * b3));
if(c == 4)
System.out.println(simplify(b2 , b1) + "/" + simplify(b4 , b3) + "=" + simplify(b2 * b4 , b1 * b3));
}
}
public static String simplify(int a,int b)
{
int max = 0;
for(int i = 0 ;i < 100 ;i ++)
{
int n = i + 1 ;
if(a % n == 0 && b % n == 0)
max = n;
}
return (String)( a / max + "/" + b / max);
}
}