您的位置:首页 > 其它

作业

2016-03-08 07:55 239 查看
---恢复内容开始---

package juxing;

public class Pig {

//    4,写一个传奇游戏中的猪类,类中有属性:颜色(color)、
//    重量(weight)、攻击力(attack)、准确度(accuracy)。
//    再写一个测试类,生成一个猪的对象,将此猪的颜色值为“白色(white)”,
//    重量为5,攻击力为50点,准确度为0.8。
//    要求输出此猪的信息格式为:一只白色的猪,重量5,攻击为50点血,准确度为0.8,
//    我好怕怕呀
//
//
//    可以加上静态,重载

String color;
double weight;
int attack;
double accuracy;
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public int getAttack() {
return attack;
}
public void setAttack(int attack) {
this.attack = attack;
}
public double getAccuracy() {
return accuracy;
}
public void setAccuracy(double accuracy) {
this.accuracy = accuracy;
}

public Pig(String color, double weight, int attack, double accuracy) {
super();
this.color = color;
this.weight = weight;
this.attack = attack;
this.accuracy = accuracy;
}
public static void main(String[] args) {

Pig zhu=new Pig("白色",5,50,0.8);
System.out.println("一只"+zhu.getColor()+"的猪,重量"+zhu.getWeight()+",攻击为"+zhu.getAttack()+"点血,准确度为"+zhu.accuracy+",我好怕怕呀");

}
}


View Code



---恢复内容结束---
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: