按要求编写Java应用程序: (1)编写西游记人物类(XiYouJiRenWu) 其中属性有:身高(height),名字(name),武器(weapon) 方法有:显示名字(printName),显示武器(printWeapon) (2)在主类的main方法中创建二个对象:zhuBaJie,sunWuKong。并分别为他 们的两个属性(name,weapon)赋值,最后分别调用printName,
package com.homework.zw; public class XiYouJiRenWu { double height; String name; String weapon; XiYouJiRenWu( String nm,String jks) { name=nm; weapon=jks; } String printName() { return name; } String printJiakesi() { return weapon; } }
package com.homework.zw; public class Xiyouji { public static void main(String[] args) { XiYouJiRenWu sunWuKong = new XiYouJiRenWu("孙悟空","如意金箍棒"); System.out.println("姓名:"+sunWuKong.printName()); System.out.println("武器:"+sunWuKong.printJiakesi()); XiYouJiRenWu zhuBaJie = new XiYouJiRenWu("猪八戒","九齿钉耙"); System.out.println("姓名:"+zhuBaJie.printName()); System.out.println("武器:"+zhuBaJie.printJiakesi()); } }