1、福建工程学院public class Instrument public void play()System.out.println(“乐器:“ );福建工程学院/小提琴 (Violin)类class Violin extends Instrument public void play()System.out.println(“小提琴(Violin)!“);福建工程学院public class InstrumentTest public static void playTest(Instrument y) y.play(); public static void main(String arg
2、s) / TODO 自动生成的方法存根Instrument instrument = new Instrument();Piano piano = new Piano();Violin violin = new Violin();playTest(instrument);playTest(piano);playTest(violin);福建工程学院int hp;int att;int def;public Native(String name, int hp, int att, int def) this.name = name;this.hp = hp;this.att = att;this
3、.def = def;public abstract void attack(Native emey);public boolean dead()if (hp0)emey.hp = emey.hp - harm;System.out.println(this.pro+this.name+“攻击“+emey .name+“,造成伤害“+harm+“ 点!“ );elseSystem.out.println(this.pro+this.name+“攻击“+emey.name+“,“+emey.name+“Miss“);独眼巨人public class Clocy extends Native St
4、ring weapon;public Clocy(String name, int hp, int att, int def,String weapon) super(name, hp, att, def);this.weapon = weapon;Overridepublic void attack(Native emey) / TODO Auto-generated method stub福建工程学院harm = this.att - emey.def;if(harm0)emey.hp = emey.hp - harm;System.out.println(“独眼巨人:“+this.nam
5、e+“ 使用“+this.weapon+“攻击“+ emey.name+“,造成伤害“+ harm+“点!“);elseSystem.out.println(“独眼巨人:“+this.name+“ 攻击“+emey.name+“,“+emey.name+“Miss“);public void disp()System.out.print(“独眼巨人:“+ this.name);super.disp();树怪类public class Tree extends Native int height;public Tree(String name, int hp, int att, int def,
6、 int height) 福建工程学院this.height = height;Overridepublic void attack(Native emey) / TODO Auto-generated method stubint harm;harm = this.att - emey.def;if(harm0)emey.hp = emey.hp - harm;System.out.println(“树怪:“+this.name+“ 使用树枝缠绕攻击“+emey.name+“,造成伤害“+harm+“ 点!“ );elseSystem.out.println(“树怪:“+this.name+
7、“ 攻击“+emey.name+“,“+emey.name+“Miss“);public void disp()System.out.print(“树怪:“+ this.name);super.disp();福建工程学院import java.util.Random;public class LoginDemo static void wait(int second) throws InterruptedExceptionThread.sleep(second * 1000);static void flight(Hero hero,ArrayList monsters) throws InterruptedExceptionint index;Random ran = new Random();Native monst;while(true)index = ran.nextInt(monsters.size();monst = monsters.get(index);wait(1);hero.attack(monst);if(monst.dead()System.out.println(“怪物“+monst.name +“死亡“);monsters.remove(index);if(monsters.size()=0)