资源描述:
《编写一个java程序片断-定义一个表示学生的类student》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、编写一个JAVA程序片断定义一个表示学生的类student,包括域"学号","班级","姓名","性别","年龄";方法"获得学号","获得班号","获得姓名","获得性别","获得年龄","修改年龄".程序如下:importjava.lang.String;importjava.lang.System;importjava.io.*;publicclassStudentManage{publicstaticvoidmain(Stringargs[]){ StudentmyStudent=newStudent(1234567,"023","hfx","male",21); System
2、.out.println(myStudent.toString());}}classStudent{longstudentNumber;StringclassNumber;StringstudentName;StringstudentSex;intstudentAge;Student(longa,Strings,Stringd,Stringf,inth){ studentNumber=a; classNumber=s; studentName=d; studentSex=f; studentAge=h;}voidgetNumber(longsno,Stringsna){
3、 if(studentName==sna) studentNumber=sno; else System.exit(1); }voidgetName(longsno,Stringsna){ if(studentNumber==sno) studentName=sna; else System.exit(1);}voidgetClass(longsno,Stringsna,Stringcn){ if(studentNumber==sno
4、
5、studentName==sna) classNumber=cn; else System.exit(1);}
6、voidgetSex(longsno,Stringsna,Strings){ if(studentNumber==sno
7、
8、studentName==sna) studentSex=s; else System.exit(1);}voidgetAge(longsno,Stringsna,inta){ if(studentNumber==sno
9、
10、studentName==sna) studentAge=a; else System.exit(1);}intchangeAge(inta){ studentAge=a; returnstudentAge;}publi
11、cStringtoString(){ Strings="studentNumber:"+studentNumber +"studentName:"+studentName +"classNumber:"+classNumber +"studentSex:"+studentSex +"studentAge:"+studentAge; returns;}}===================================================================================编写一个Java程序片断,以定义一个表示
12、学生的类Student。这个类的属性有“学号”、“班号”、“姓名”、“性别”、“年龄”,方法有“获得学号”、“获得班号”、“获得性别”、“获得姓名”、“获得性别”、“获得年龄”。classstudent{privateStringxuehao;privateStringbanhao;privateStringxingming;privateStringxingbie;privateintnianling;publicstudent(Stringx,Stringb,Stringm,Stringb1,intn){ this.xuehao=x; this.banhao=b; this.xi
13、ngming=m; this.xingbie=b1; this.nianling=n;}publicStringgetxuehao(){ returnxuehao;}publicStringgetbanhao(){ returnbanhao;}publicStringgetxingming(){ returnxingming;}publicStringgetxingbie(){ returnxingbie;}