2 Star 0 Fork 0

古月立/王志康和胡靖宇的java库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
StudentManager.java 4.67 KB
一键复制 编辑 原始数据 按行查看 历史
古月立 提交于 2024-12-04 00:00 . java
package week13;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class StudentManager {
Scanner sc = new Scanner(System.in);
ArrayList<StudentClass> studentClasses = new ArrayList<StudentClass>();
Random rd = new Random();
public void exportGrade(StudentClass studentClass) {
System.out.println("导出成绩");
System.out.println("=====================");
ArrayList<Student> students = studentClass.getStudents();
for (int i = 0; i < students.size(); i++) {
System.out.println(students.get(i).getName() + " " + students.get(i).getMarks());
}
}
public Object[] randomChooseStudent(int classId) {
StudentClass studentClass = studentClasses.get(classId - 1);
int studentId = rd.nextInt(studentClass.getStudents().size());
Student student = studentClass.getStudents().get(studentId);
return new Object[]{student.getName(), student.getId()};
}
public void studentGradeManagement(StudentClass studentClass) {
}
public void studentAttendanceRecord(StudentClass studentClass) {
}
public void addStudent(String name, int id, int classId) {
StudentClass studentClass = studentClasses.get(classId - 1);
studentClass.getStudents().add(new Student(name, id));
}
public Object[][] listStudents(Integer classId) {
StudentClass studentClass = studentClasses.get(classId - 1);
Object[][] students = new Object[studentClass.getStudents().size()][2];
for (int i = 0; i < studentClass.getStudents().size(); i++) {
students[i][1] = studentClass.getStudents().get(i).getId();
students[i][0] = studentClass.getStudents().get(i).getName();
}
return students;
}
public Object[][] listGroups(int classId) {
StudentClass studentClass = studentClasses.get(classId - 1);
Object[][] groups = new Object[studentClass.getGroups().size()][5];
for (int i = 0; i < studentClass.getGroups().size(); i++) {
groups[i][0] = "小组" + (i + 1);
groups[i][1] = studentClass.getGroups().get(i).getStu1().getName();
groups[i][2] = studentClass.getGroups().get(i).getStu1().getId();
groups[i][3] = studentClass.getGroups().get(i).getStu2().getName();
groups[i][4] = studentClass.getGroups().get(i).getStu2().getId();
}
return groups;
}
public void addNewGroup(String name1, int id1, String name2, int id2, int classId) {
Student student1 = new Student(name1, id1);
Student student2 = new Student(name2, id2);
StudentClass studentClass = studentClasses.get(classId - 1);
studentClass.getStudents().add(student1);
studentClass.getStudents().add(student2);
studentClass.getGroups().add(new Group(student1, student2));
}
//班级管理
public void addNewClass() {
studentClasses.add(new StudentClass());
}
public Object[][] listClasses() {
Object[][] classes = new Object[studentClasses.size()][2];
for (int i = 0; i < studentClasses.size(); i++) {
classes[i][0] = "班级" + (i + 1);
classes[i][1] = studentClasses.get(i).getStudents().size();
}
return classes;
}
public String[] getAllClasses() {
studentClasses.add(new StudentClass());
String[] classes = new String[studentClasses.size()];
for (int i = 0; i < studentClasses.size(); i++) {
classes[i] = "班级" + (i + 1);
}
return classes;
}
public void recordGrade(int className, String name, int id, double grade) {
StudentClass studentClass = studentClasses.get(className - 1);
for (int i = 0; i < studentClass.getStudents().size(); i++) {
if (studentClass.getStudents().get(i).getId() == id&&studentClass.getStudents().get(i).getName().equals(name)) {
studentClass.getStudents().get(i).setMarks(grade);
break;
}
}
}
public Object[][] getGradesList(int classNum) {
StudentClass studentClass = studentClasses.get(classNum - 1);
Object[][] grades = new Object[studentClass.getStudents().size()][3];
for (int i = 0; i < studentClass.getStudents().size(); i++) {
grades[i][0] = studentClass.getStudents().get(i).getId();
grades[i][1] = studentClass.getStudents().get(i).getName();
grades[i][2] = studentClass.getStudents().get(i).getMarks();
}
return grades;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/huyul/hello-git.git
git@gitee.com:huyul/hello-git.git
huyul
hello-git
王志康和胡靖宇的java库
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385