编写一个程序片断定义一个表示学生的类
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
编写一个JAVA程序片断定义一个表示学生的类student,包括域"学号","班级","姓名","性别","年龄";方法"获得学号","获得班号","获得姓名","获得性别","获得年龄","修改年龄".
程序如下:
import
import
import .*;
public class StudentManage
{
public static void main(String args[])
{
Student myStudent=new Student(1234567,"023","hfx","male",21);
}
}
class Student
{
long 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
(1);
}
void getName(long sno,String sna)
{
if(studentNumber==sno)
studentName=sna;
else
(1);
}
void getClass(long sno,String sna,String cn) {
if(studentNumber==sno||studentName==sna) classNumber=cn;
else
(1);
}
void getSex(long sno,String sna,String s) {
if(studentNumber==sno||studentName==sna) studentSex=s;
else
(1);
}
void getAge(long sno,String sna,int a)
{
if(studentNumber==sno||studentName==sna) studentAge=a;
else
(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 student{
private 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){ = x;
= b;
= m;
= b1;
= 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 Dome4{
public static void main(String args[]){
student s1 = new student("02122168","12","安静","男",24);
}
}