姜维纹身手稿:帮忙做道JAVA题

来源:百度文库 编辑:高考问答 时间:2024/04/30 03:34:17
定义一个类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());
}
}

}