按要求编写Java应用程序: (1)编写西游记人物类(XiYouJiRenWu) 其中属性有:身高(height),名字(name),武器(weapon) 方法有:显示名字(printName),显示武器(printWeapon) (2)在主类的main方法中创建二个对象:zhuBaJie,sunWuKong。并分别为他 们的两个属性(name,weapon)赋值,最后分别调用printName,

package com.hanqi.test;

public class xiyoujirenwu {
	private double height;// 身高

	private String name;// 名称

	private String weapon;// 武器

	public double getHeight() {
		return height;
	}

	public void setHeight(double height) {
		if(height<=10)
		{
			System.out.println("身高输入有误");
		}
		this.height = height;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getWeapon() {
		return weapon;
	}

	public void setWeapon(String weapon) {
		this.weapon = weapon;
	}

  

package com.hanqi.test;

public class Test04 {

    public static void main(String[] args) {
        
        xiyoujirenwu swk=new xiyoujirenwu();
        swk.setName("孙悟空");
        System.out.println("人物"+swk.getName());
        swk.setHeight(20);
        System.out.println("身高:"+swk.getHeight());
    }

}

 

posted @ 2016-09-18 22:18  -加勒比海带  阅读(4508)  评论(0编辑  收藏  举报