按要求编写Java应用程序。
(1)创建一个叫做People的类:
属性:姓名、年龄、性别、身高
行为:说话、计算加法、改名
编写能为所有属性赋值的构造方法;
(2)创建主类:
创建一个对象:名叫“张三”,性别“男”,年龄18岁,身高1.80;
让该对象调用成员方法:
说出“你好!”
计算23+45的值
将名字改为“李四”
package lianxiti9dao13; public class People { private String name; public String getName() { return name; } public void setName(String name) { this.name=name; } private int age; public int getAge() { return age; } public void setAge(int age) { this.age = age; } private String xingbie; public String getXingbie() { return xingbie; } public void setXingbie(String xingbie) { this.xingbie=xingbie; } private double height; public double getHeight() { return height; } public void setHeight(double height) { this.height = height; } People(String name,String xingbie,int age,double height) { this.name=name; this.xingbie=xingbie; this.age=age; this.height=height; } public void shuohua(String a) { System.out.println(a); } public void jisuanjiafa( int b,int c) { System.out.println(b+c); } public static void main(String[] args) { People p1=new People("张三","男",18,1.80); System.out.println(p1.getName()); System.out.println(p1.getXingbie()); System.out.println(p1.getAge()); System.out.println(p1.getHeight()); p1.shuohua("你好"); p1.jisuanjiafa(23,45); p1.setName("李四"); System.out.println(p1.getName()); } }