求一个java编程题的答案

编写满足以下要求的类:①Student类:含id(学号)、name(姓名)、isMale(是否为男性)、birth(生日)等私有字段(注意合理设置各字段的类型)。②使用E... 编写满足以下要求的类:
①Student类:含id(学号)、name(姓名)、isMale(是否为男性)、birth(生日)等私有字段
(注意合理设置各字段的类型)。
②使用Eclipse自动产生Student类各字段的getter/setter方法。
③使用Eclipse自动产生Student类的默认及完全构造方法。
④使用Eclipse自动产生Student类重写Object根类的toString方法的代码框架,并返
回由各字段信息组成的字符串。
⑤StudentTest类:在其main方法中编写合适代码测试Student类
展开
 我来答
yinfengnong
2019-06-22 · TA获得超过5618个赞
知道大有可为答主
回答量:2344
采纳率:89%
帮助的人:2247万
展开全部
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
class Student {

private String id;

private String name;

private boolean isMale;

private Date birth;
public Student() {
super();
}
public Student(String id, String name, boolean isMale, Date birth) {
super();
this.id = id;
this.name = name;
this.isMale = isMale;
this.birth = birth;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isMale() {
return isMale;
}
public void setMale(boolean isMale) {
this.isMale = isMale;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", isMale=" + isMale + ", birth=" + birth + "]";
}
}
public class StudentTest {

public static void main(String[] args) throws ParseException {

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");

Student stu = new Student("00001", "Tom", true, dateFormat.parse("2000-01-01"));
System.out.println(stu);
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式