6.按要求编写Java应用程序: (1)定义西游记人物类,有属性:名字、身高和武器, 有构造方法初始化属性,还有输出人物详细信息的方法。 (2)在主类的main方法中创建两个西游记
public class Peoper { String name; int height; String weapon; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } public String getWeapon() { return weapon; } public void setWeapon(String weapon) { this.weapon = weapon; } public Peoper(String name, int height, String weapon) { super(); this.name = name; this.height = height; this.weapon = weapon; } } package gh; public class text6 { public static void main(String[] args) { Peoper sunwukong= new Peoper("孙悟空",165,"金箍棒"); Peoper zhubajie=new Peoper("猪八戒",187,"耙子"); System.out.println(sunwukong.getName()+" "+sunwukong.getHeight()+" "+sunwukong.getWeapon()); System.out.println(zhubajie.getName()+" "+ zhubajie.getHeight()+" "+zhubajie.getWeapon()); } }