求Java作业,大神帮帮忙!急急急
1个回答
展开全部
public class Hero {
int curLife;
int maxLife;
public Hero(int max){
this.maxLife=max;
}
public void gx(int max){
Random r = new Random();
int n = r.nextInt(10);
if (n >= 2 && n < 5) {
this.maxLife=max;
}
}
public int getCurLife() {
return curLife;
}
public void setCurLife(int curLife) {
this.curLife = curLife;
}
public int getMaxLife() {
return maxLife;
}
public void setMaxLife(int maxLife) {
this.maxLife = maxLife;
}
}
public static void main(String[] args) {
Random r = new Random();
int n = r.nextInt(100);
Hero hero =new Hero(100);
hero.setCurLife(n);
System.out.println(hero.getCurLife());
if(hero.getCurLife()<hero.getMaxLife()*0.2){
hero.gx(100);
}
}
int curLife;
int maxLife;
public Hero(int max){
this.maxLife=max;
}
public void gx(int max){
Random r = new Random();
int n = r.nextInt(10);
if (n >= 2 && n < 5) {
this.maxLife=max;
}
}
public int getCurLife() {
return curLife;
}
public void setCurLife(int curLife) {
this.curLife = curLife;
}
public int getMaxLife() {
return maxLife;
}
public void setMaxLife(int maxLife) {
this.maxLife = maxLife;
}
}
public static void main(String[] args) {
Random r = new Random();
int n = r.nextInt(100);
Hero hero =new Hero(100);
hero.setCurLife(n);
System.out.println(hero.getCurLife());
if(hero.getCurLife()<hero.getMaxLife()*0.2){
hero.gx(100);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询