帮我写个java的person类

来源:百度知道 编辑:UC知道 时间:2024/06/25 07:39:09
写一个Person类
我们需要构建家庭的概念 ,一个家庭要包括一个父亲一个母亲 一些孩子 .
用Vector类去保存孩子的信息 , Family类应该提供以下方法
合适的初始化构造方法.
设置并获得双亲属性的方法.
设置并获得某个孩子属性的方法 ,并且他要以参数传递.就如以下方法
public void setChildAge(int no, int age)
public int getChildAge(int no)
两个以上的方法各自被用来设置并获得第几个孩子的年龄
增加一个孩子的方法 并以人的实例作为参数传递.
删除一个孩子的方法 以一个整形数作为参数来表示第几个孩子被删除
一个toString 方法:当你用toString方法把一个家庭的实例的参数改变成一个字符串时,你将需要使用循环来处理孩子元素.
对Family class提供averageAge 方法来计算一个家庭中孩子的平均年龄
如果任何的方法传递了非法的值时 一个InvalidFamilyAttribute异常将被抛出
举个例子:删除一个孩子后 孩子的数比被删前多
测试一下编写的程序的正确性 程序应实现一下功能:
Set the attribute of father
Set the attribute of mother
Set the attribute of the given child
Add a child
Delete the given child
Show all the information of the family
Calculate the average age of the children
把一个家庭的所有属性保存到一个文件中并能从中读取 ,并可以用FileDialog class来选择一个文件,
当从一个文件载入一个家庭时,当前家庭的所有属性将被替代.
程序应当能捕捉到exception InvalidFamilyAttribute.

唉~~你这不是一个问题,而是一堆问题啊~~
要写几个类啊?需求描述的也不太明确

想起了上学时候做课程设计的时光…… 大概需要4个类,要是需要就留个邮箱号吧