编写一个JAVA程序片断 定义一个表示学生的类student(4页).doc
-编写一个JAVA程序片断 定义一个表示学生的类student-第 4 页编写一个JAVA程序片断 定义一个表示学生的类student,包括域"学号","班级","姓名","性别","年龄"方法"获得学号","获得班号","获得姓名","获得性别","获得年龄","修改年龄".程序如下:public class StudentManagepublic static void main(String args) Student myStudent=new Student(1234567,"023","hfx","male",21);class Studentlong studentNumber;String classNumber;String studentName;String studentSex;int studentAge;Student(long a,String s,String d,String f,int h) studentNumber=a; classNumber=s; studentName=d; studentSex=f; studentAge=h;void getNumber(long sno,String sna) if(studentName=sna) studentNumber=sno; else System.exit(1); void getName(long sno,String sna) if(studentNumber=sno) studentName=sna; else System.exit(1);void getClass(long sno,String sna,String cn) if(studentNumber=sno|studentName=sna) classNumber=cn; else System.exit(1); void getSex(long sno,String sna,String s) if(studentNumber=sno|studentName=sna) studentSex=s; else System.exit(1); void getAge(long sno,String sna,int a) if(studentNumber=sno|studentName=sna) studentAge=a; else System.exit(1); int changeAge(int a) studentAge=a; return studentAge; public String toString() String s="studentNumber:"+studentNumber +"n studentName:"+studentName +"n classNumber:"+classNumber +"n studentSex:"+studentSex +"n studentAge:"+studentAge; return s;编写一个Java程序片断,以定义一个表示学生的类Student。这个类的属性有“学号”、“班号”、“姓名”、“性别”、“年龄”,方法有“获得学号”、“获得班号”、“获得性别”、“获得姓名”、“获得性别”、“获得年龄”。class studentprivate String xuehao;private String banhao;private String xingming;private String xingbie;private int nianling;public student(String x,String b,String m,String b1,int n) this.xuehao = x; this.banhao = b; this.xingming = m; this.xingbie = b1; this.nianling = n;public String getxuehao() return xuehao;public String getbanhao() return banhao;public String getxingming() return xingming;public String getxingbie() return xingbie;public int getnianling() return nianling;public String toString() return xuehao+" "+banhao+" "+xingming+" "+xingbie+" "+nianling;public class Dome4public static void main(String args) student s1 = new student("02122168","12","安静","男",24); System.out.println(s1.toString();