package com.sr.mll;
class StudentId {
private String name;
private int id;
private String classroom;
private int totalScore;
private int ranking;
public StudentId () {
}
public StudentId (String name, int id, String classroom) {
this.name = name;
this.id = id;
this.classroom = classroom;
}
public StudentId (String name, int id, String classroom, int totalScore, int ranking) {
this(name, id, classroom);
this.totalScore = totalScore;
this.ranking = ranking;
}
public String getName() {
return name;
}
public int getId() {
return id;
}
public String getClassroom() {
return classroom;
}
public int getTotalScore() {
return totalScore;
}
public int getRanking() {
return ranking;
}
public void printId () {
String str = this.name + "\t\t" + this.id + "\t" + this.classroom;
System.out.println(str + "\t" + this.totalScore + "\t\t" + this.ranking);
}
}
class StudentList {
public StudentList () {
}
int number = 0;
StudentId[] list = new StudentId[60]; //定义并初始化对象数组
public void addNumber (StudentId stu) {
list[number] = stu;
number++;
}
public void print () {
System.out.println("姓名" + "\t\t学号" + "\t\t班级" + "\t\t总分" + "\t\t排名");
for (int i = 0; i < number; i++) {
list[i].printId();
}
}
}
public class Zh05 {
public static void main(String[] args) {
StudentList std = new StudentList();
StudentId lb = new StudentId("刘备",2024022,"C666",579,134);
StudentId zs = new StudentId("张三",2024025,"C667",555,200);
StudentId ls = new StudentId("李四",2024038,"C659",498,312);
std.addNumber(lb); //将对象存入数组
std.addNumber(zs);
std.addNumber(ls);
std.print();
}
}
以上是自己写的一段代码,记录学习情况,如有不对,请多见谅。