JAVA题:定义People及其对象
文章作者 100test 发表时间 2007:03:26 17:58:29
来源 100Test.Com百考试题网
定义一个类People,成员变量有姓名,出生日期,性别,身高,体重等,成员方法有计算年龄,并创建该类的对象.
import java.util.Scanner.
public class People
{
private int[] age.
private double[] height.
private double[] weight.
private String[] sex.
private Date[] birthday.
public People (int n)
{
this.age = new int[n].
this.height = new double[n].
this.weight = new double[n].
this.sex = new String[n].
this.birthday = new Date[n].
Scanner in = new Scanner(System.in).
for (int i = 0. i< n. i )
{
System.out.println("Please input the age, height, weight, sex,and birthday").
age[n] = in.nextInt().
height [n] = in.nextDouble().
weight [n] = in.nextDouble().
sex[n] = in.next().
birthday[n] = new Date(in.nextInt(),in.nextInt(),in.nextInt()).
}
}
}