设计一个类Support (辅助英雄)继承Hero,提供一个heal(治疗)方法
对Support的heal方法进行重载
heal()
heal(Hero h) //为指定的英雄加血
heal(Hero h, int hp) //为指定的英雄加了hp的血
设计一个类Armor护甲
继承Item类,并且额外提供一个属性ac: 护甲等级 int类型
实例化出两件护甲
名称 价格 护甲等级
布甲 300 15
锁子甲 500 40
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
class day0916 { public static void main(String[] args) { Armor bujia=new Armor(); Armor suozijia=new Armor(); bujia.name="布甲"; bujia.price=300; bujia.ac=15; suozijia.name="锁子甲"; suozijia.price=500; suozijia.ac=40; System.out.println("名字:"+bujia.name+" 价格:"+bujia.price+" 护甲等级:"+bujia.ac); System.out.println("名字:"+suozijia.name+" 价格:"+suozijia.price+" 护甲等级:"+suozijia.ac); Hero timo=new Hero(); timo.name="提莫"; timo.hp=333.0f; timo.armor=14.0f; timo.moveSpeed=330; timo.outPut(); System.out.println("*****************************"); Hero gailun=new Hero(); gailun.name="盖伦"; gailun.hp=616.0f; gailun.armor=27.0f; gailun.moveSpeed=250; gailun.outPut(); System.out.println("*****************************"); Support naima=new Support(); naima.name="众星之子"; naima.hp=345f; naima.armor=30f; naima.moveSpeed=400; naima.heal(timo); System.out.println("*****************************"); System.out.println("治疗后"); timo.outPut(); naima.heal(gailun); System.out.println("*****************************"); System.out.println("治疗后"); gailun.outPut();
} } class Item//物品类 { String name; int price; } class Armor extends Item { int ac; }
class Hero { String name; float hp; float armor; int moveSpeed; void outPut() { System.out.println("英雄名称:"+name+"\n英雄生命值:"+hp+"\n英雄护甲:"+armor+"\n移动速度:"+moveSpeed); } } class Support extends Hero { public static String name; public static void heal(Hero...heros) { for (int i=0;i<heros.length;i++ ) { heros[i].hp+=150; System.out.println(name+"给"+heros[i].name+"治疗了150生命值"); } } }
|
;