源码
class Demo1_MachineArmor{
public static void main(String[] args){
MachineArmor ma1 = new MachineArmor("make001", 99, 77);
ma1.show();
ma1.setAttack(122);
ma1.setDefend(144);
ma1.show();
MachineArmor ma48 = new MachineArmor("make048", 89, 45);
ma48.show();
}
}
/**
机甲类:
成员变量:
model: 型号
attack: 攻击力
defend: 防御力
构造方法:
无参
有参(型号,攻击力, 防御力)
成员方法:
setModel:设置型号
setAttack:设置攻击力
setDefend:设置防御力
getModel:获取型号
getAttack:获取攻击力
getDefend:获取防御力
*/
class MachineArmor{
private String model;
private int attack;
private int defend;
public MachineArmor(){}
public MachineArmor(String model, int attack, int defend){
this.model = model;
this.attack = attack;
this.defend = defend;
}
public void setModel(String model){
this.model = model;
}
public void setAttack(int attack){
this.attack = attack;
}
public void setDefend(int defend){
this.defend = defend;
}
public String getModel(){
return this.model;
}
public int getAttack(){
return this.attack;
}
public int getDefend(){
return this.defend;
}
public void show(){
System.out.println(this.model + ": " + this.attack + " --- " + this.defend);
}
}
输出
H:\Code\Java\learn\07day>java Demo1_MachineArmor
make001: 99 --- 77
make001: 122 --- 144
make048: 89 --- 45