java 程序问题 急!!!!!!!!

来源:百度知道 编辑:UC知道 时间:2024/07/04 01:10:17
定义学生类,类中包含姓名与学生属性及静态属性stuCode,stuCode作为学号最后一位编码(假定学号为2010030x,其中x为尾码编码)每次调用构造方法,对静态属性stuCode做自增运算;静态方法getStuCode()的功能为转换静态属性值为字符串类型并返回,showInfo()方法功能为显示学生对象信息,主类中包含入口方法main(),方法中顺次创建3个学生对象并显示各个对象的信息!

public class Student {

//学号固定部分,此处定义为常量
private final static String stuNum = "2010030";

//学号尾数
private static int stuCode;

//学生姓名
private String name; //姓名

//构造函数,初始化对象的name属性,并将静态变量stuCode自增
public Student(String name){
this.name = name;
stuCode++;
}

//将静态变量学号尾数转换为字符串并返回
public static String getStuCode(){
return Integer.toString(stuCode) + ;
}

//获得学生信息,此处增加了参数为Student对象(目的是灵活)
public String showInfo(Student student){
String stuInfo = "姓名:" + student.name + " " + "学号:" + stuNum+stuCode;
return stuInfo;

}

//主函数
public static void main(String argc[]){
Student stu1 = new Student("张三");
System.out.println(stu1.showInfo(stu1));
Student stu2 = new Student("李四");
System.out.println(stu2.showInf