JAVA题:定义People及其对象Java认证考试

文章作者 100test 发表时间 2009:04:30 07:58:35
来源 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()).
}
}

}



相关文章


Java认证模拟题及分析3Java认证考试
Java认证模拟题及分析2Java认证考试
Java认证模拟题及分析1Java认证考试
JAVA题:定义People及其对象Java认证考试
JAVA题库:传递引用的经典Java认证考试
排序和金额转换·两道JAVA编程题及答案Java认证考试
JAVA题库:5道JAVA题Java认证考试
JAVA题库:26道基础知识题(2)Java认证考试
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛