public interface Number {
public int nextInt();
}
2:
import java.util.Random;
public class Cat implements Number{
private String name;
private char sex;
public Cat() {
}
public Cat(String aNmae, char aSex) {
this.name = aNmae;
this.sex = aSex;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public int nextInt() {
int aInt;
aInt = new Random().nextInt(3);
return aInt;
}
}
3:
import java.util.Random;
public class Mouse implements Number{
private String name;
private char sex;
public Mouse() {
}
public Mouse(String aNmae, char aSex) {
this.name = aNmae;
this.sex = aSex;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public int nextInt() {
int aInt;
aInt = new Random().nextInt(3);
return aInt;
}
}
4:
public class Stage {
public static void main(String[] args) {
Cat cat = new Cat("Tom" , 'M');
Mouse mouse = new Mouse("Jerry", 'M');
int tint;
int mint;
tint = cat.nextInt();
mint = mouse.nextInt();
String result = ((tint > mint)? "抓到" : "跑了");
System.out.println("结果为 : " + result);
}
} |