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