public class Hero{ public static void main(String[] args) { String need = "设计英雄类 他们都有名字,hp,护甲,移动速度等"; // create Hero Heros 剑圣 = new Heros(); 剑圣.setName("无极剑圣"); String jsName = 剑圣.getName(); 剑圣.setHp(430); int jsHp = 剑圣.getHp(); 剑圣.setArmor(17); int jsArmor = 剑圣.getArmor(); 剑圣.setMoveSpeed(1.56); double jsMoveSpeed = 剑圣.getMoveSpeed(); System.out.println("===============英雄信息:==============="); System.out.println(">>>>>>英雄姓名:"+jsName); System.out.println(">>>>>>英雄血量:"+jsHp); System.out.println(">>>>>>英雄护甲:"+jsArmor); System.out.println(">>>>>>移动速度:"+jsMoveSpeed); System.out.println("===============英雄 die:==============="); } } class Heros{ private String name; //血量 private int hp; //护甲 private int armor; private double moveSpeed; public void setName(String name) { this.name = name; } public String getName() { return this.name; } public void setHp(int hp) { if(hp > 0) { if(hp < 500) { this.hp = hp; }else { System.out.println("属性初始外挂!"); } }else { System.out.println("英雄初始血量不能小于0"); } } public int getHp() { return this.hp; } public void setArmor(int armor) { this.armor = armor; } public int getArmor() { return this.armor; } public void setMoveSpeed(double moveSpeed) { this.moveSpeed = moveSpeed; } public double getMoveSpeed() { return this.moveSpeed; } }
===============英雄信息:===============
>>>>>>英雄姓名:无极剑圣
>>>>>>英雄血量:430
>>>>>>英雄护甲:17
>>>>>>移动速度:1.56
===============英雄 die:===============