``````各成员变量的get方法与set方法

//要求随机生成不同种类的外星人
//比如1%的概率生成的外星人对象是boss的属性，hp=10000，dam=2000，move=5
//比如10%的概率生成的是大怪属性，hp=5000，dam=5000，move=2
//比如80%的概率生成是小怪，hp=500，dam=100，move=1
//概率可以用随机数加范围实现，比如随机一个1-100之间的数，那么random==1就是1%的概率，random<10就是10%
//输出相关的数据信息。
}
``````

``````     成员方法 fire()
``````

1个回答

public class Monster {
private String hp;
private String damage;
private String speed;

``````public Monster(){
int x = (int)(Math.random()*100+1);
System.out.println("x"+x);
if (x ==1){
this.hp = "10000";
this.damage = "2000";
this.speed = "5";
}else if (x > 1 && x <= 11){
this.hp = "5000";
this.damage = "500";
this.speed = "2";
}else{
this.hp = "500";
this.damage = "200";
this.speed = "1";
}
}

public String getHp() {
return hp;
}
public void setHp(String hp) {
this.hp = hp;
}
public String getDamage() {
return damage;
}
public void setDamage(String damage) {
this.damage = damage;
}
public String getSpeed() {
return speed;
}
public void setSpeed(String speed) {
this.speed = speed;
}
``````

}

public class Gun implements Weapon{
private String price;
private String damage;
private String distance;
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getDamage() {
return damage;
}
public void setDamage(String damage) {
this.damage = damage;
}
public String getDistance() {
return distance;
}
public void setDistance(String distance) {
this.distance = distance;
}
@Override
public void fire() {
// TODO Auto-generated method stub
System.out.println("枪开火");
}
@Override
// TODO Auto-generated method stub
System.out.println("枪装填");
}
}

public interface Weapon {
public void fire();