编写一个Java程序片断定义一个表示学生的类student,包括域“学号”、”班号”、“姓名”、“性别”、“年

2024-11-27 12:13:41
推荐回答(3个)
回答1:

public class Student{
String number;
String classNum;
String name;
String sex;
int age;

public Student() {

}

public Student(String number, String classNum, String name, String sex,
int age) {
super();
this.number = number;
this.classNum = classNum;
this.name = name;
this.sex = sex;
this.age = age;
}

public String getNumber() {
return number;
}

public void setNumber(String number) {
this.number = number;
}

public String getClassNum() {
return classNum;
}

public void setClassNum(String classNum) {
this.classNum = classNum;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getSex() {
return sex;
}

public void setSex(String sex) {
this.sex = sex;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}
}这问题很基础的,多看一下吧

回答2:

package three;

public class Student {
private int id;
private int classNumber;
private String name;
private String sex="m";
private int age;
public Student() {
super();
// TODO Auto-generated constructor stub
}
public Student(int id, int classNumber, String name, String sex, int age) {
super();
this.id = id;
this.classNumber = classNumber;
this.name = name;
this.sex = sex;
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getClassNumber() {
return classNumber;
}
public void setClassNumber(int classNumber) {
this.classNumber = classNumber;
}

}

回答3:

楼上说的很对。 这个就是简单的javabean
但是要注意的是 性别最好用boolean年龄要用int 但是一般都是存放生日通过计算得出年龄 所以这里最好定义成Date