/*
* 2.定义一个表示学生的类Student,包括属性“学号”、“班号”、“姓名”、“性别”、“年龄”;
* 方法“获得学号”、“获得班号”、 “获得姓名”、“获得性别”、 “获得年龄”、 “修改年龄”。
* 在main()中创建Student类对象,测试自定义类。
* 2.定义一个表示学生的类Student,包括属性“学号”、“班号”、“姓名”、“性别”、“年龄”;
* 方法“获得学号”、“获得班号”、 “获得姓名”、“获得性别”、 “获得年龄”、 “修改年龄”。
* 在main()中创建Student类对象,测试自定义类。
*/
/*
* 2.定义一个表示学生的类Student,包括属性“学号”、“班号”、“姓名”、“性别”、“年龄”;
* 方法“获得学号”、“获得班号”、 “获得姓名”、“获得性别”、 “获得年龄”、 “修改年龄”。
* 在main()中创建Student类对象,测试自定义类。
*/
//创建学生类
class Student_C{
private int num_s; //学号
private int num_c; //班号
private int age; //年龄
private String name; //姓名
private String sex; //性别
//构建带参构造
public Student_C(int num_s, int num_c, int age, String name, String sex) {
this.num_s = num_s;
this.num_c = num_c;
this.age = age;
this.name = name;
this.sex = sex;
}
//获得学号
public int getNum_s() {
return num_s;
}
public void setNum_s(int num_s) {
this.num_s = num_s;
}
//获得班号
public int getNum_c() {
return num_c;
}
public void setNum_c(int num_c) {
this.num_c = num_c;
}
//获得年龄
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int regetAge() {
return age;
}
public void changeAge(int age) {
this.age = age;
}
//获得姓名
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 class Student {
public static void main(String[] args) {
Student_C sc = new Student_C(28, 2, 18, "RJF", "boy");
System.out.println("学号:"+sc.getNum_s()+";\n班级:"+sc.getNum_c()+";\n年龄:;"+sc.getAge());
System.out.println("姓名"+sc.getName()+";\n性别"+sc.getSex()+".");
System.out.println("----------------");
//改年龄
sc.changeAge(20);
System.out.println("学号:"+sc.getNum_s()+";\n班级:"+sc.getNum_c()+";\n年龄:;"+sc.regetAge());
System.out.println("姓名"+sc.getName()+";\n性别"+sc.getSex()+".");
}
}