Home >Java >javaTutorial >How to implement a simple student performance file management system in Java?
Student performance file management system source code:
student
public class students{ private String name; private String number; private int chinascore; private int mathscore; private int englishscore; private int physcore; public students(String name, String number, int chinascore, int mathscore, int englishscore, int physcore) { this.name = name; this.number = number; this.chinascore = chinascore; this.mathscore = mathscore; this.englishscore = englishscore; this.physcore = physcore; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public int getChinascore() { return chinascore; } public void setChinascore(int chinascore) { this.chinascore = chinascore; } public int getMathscore() { return mathscore; } public void setMathscore(int mathscore) { this.mathscore = mathscore; } public int getEnglishscore() { return englishscore; } public void setEnglishscore(int englishscore) { this.englishscore = englishscore; } public int getPhyscore() { return physcore; } public void setPhyscore(int physcore) { this.physcore = physcore; } }
database
import java.util.ArrayList; import java.util.List; public class database { List<students> studentsList = new ArrayList<>(); public database() { studentsList.add(new students("张三", "1", 1, 1, 1, 1)); studentsList.add(new students("李四", "2", 8, 2, 2, 2)); studentsList.add(new students("王五", "3", 1, 3, 3, 3)); studentsList.add(new students("赵六", "4", 6, 4, 4, 4)); } public List<students> getStudentsList() { return studentsList; } public void setStudentsList(List<students> studentsList) { this.studentsList = studentsList; } }
studentdao
import java.util.List; import java.util.Scanner; public class studentdao { database database; public studentdao(database dataBase) { this.database = dataBase; } //对全部学生信息打印 public void print() { List<students> list = database.getStudentsList(); System.out.println("学生学号:" + "学生姓名" + " 语文:" + "数学:" + "英语:" + "物理:"+"学生总分"); for (students students : database.getStudentsList()) { int x=students.getChinascore()+students.getMathscore()+students.getEnglishscore()+students.getPhyscore(); System.out.println("" + students.getNumber() + " " + students.getName() + " " + students.getChinascore() + " " + students.getMathscore() + " " + students.getEnglishscore() + " " + students.getPhyscore()+" "+x); } for(int i=0;i<=list.size();i++){ int x=list.get(i).getChinascore()+list.get(i).getMathscore() +list.get(i).getEnglishscore()+list.get(i).getPhyscore(); System.out.println((i+1)+list.get(i).getNumber()+list.get(i).getName()+list.get(i).getChinascore()+list.get(i).getMathscore() +list.get(i).getEnglishscore()+list.get(i).getPhyscore() +x); } } //添加新的学生 public void add() { String number; String name; int grade1; int grade2; int grade3; int grade4; Scanner scanner = new Scanner(System.in); System.out.println("输入学生的学号:"); number = scanner.next(); System.out.println("输入学生的姓名:"); name = scanner.next(); System.out.println("输入学生的语文成绩:"); grade1 = scanner.nextInt(); System.out.println("输入学生的数学成绩:"); grade2 = scanner.nextInt(); System.out.println("输入学生的英语成绩:"); grade3 = scanner.nextInt(); System.out.println("输入学生的物理成绩:"); grade4 = scanner.nextInt(); students students = new students(name, number, grade1, grade2, grade3, grade4); List<students> studentsList = database.getStudentsList(); studentsList.add(students); } //输入姓名或者学号来查询学生信息 public void searchstudent() { Scanner scanner = new Scanner(System.in); findbynumber(); } //通过输入学号来查询信息 public void findbynumber() { Scanner scanner = new Scanner(System.in); System.out.println("输入学生的学号:"); String number = scanner.next(); for (students students : database.getStudentsList()) { if (students.getNumber().equals(number)) { System.out.println("学生学号:" + students.getNumber() + "学生姓名:" + students.getName() + "语文:" + students.getChinascore() + "数学:" + students.getMathscore() + "英语:" + students.getEnglishscore() + "物理:" + students.getPhyscore()); } } } //通过学号来修改科目成绩 public void changescore() { Scanner scanner = new Scanner(System.in); System.out.println("输入学号:"); String number = scanner.next(); students students = null; for (students a : database.getStudentsList()) { if (a.getNumber().equals(number)) { students = a; } } if (students != null) { System.out.println("查找成功!"); System.out.println("学生学号:" + students.getNumber() + "学生姓名:" + students.getName() + "语文:" + students.getChinascore() + "数学:" + students.getMathscore() + "英语:" + students.getEnglishscore() + "物理:" + students.getPhyscore()); System.out.println("输入要修改的语文的成绩:"); int grade1 = scanner.nextInt(); System.out.println("输入要修改的数学的成绩:"); int grade2 = scanner.nextInt(); System.out.println("输入要修改的英语的成绩:"); int grade3 = scanner.nextInt(); System.out.println("输入要修改的物理的成绩:"); int grade4 = scanner.nextInt(); students.setChinascore(grade1); students.setMathscore(grade2); students.setEnglishscore(grade3); students.setPhyscore(grade4); System.out.println("修改完成!"); System.out.println("学生学号:" + students.getNumber() + "学生姓名:" + students.getName() + "语文:" + students.getChinascore() + "数学:" + students.getMathscore() + "英语:" + students.getEnglishscore() + "物理:" + students.getPhyscore()); } else { System.out.println("未找到该学生!"); } } //双向冒泡排序 public List<students> bub(List<students> studentList) { List<students> list = database.getStudentsList(); students student = null; int left = 0, right = database.getStudentsList().size() - 1; while (left < right) { for (int i = left + 1; i <= right; i++) { if (list.get(left).getChinascore() + list.get(left).getMathscore() + list.get(left).getEnglishscore() + list.get(left).getPhyscore() < list.get(i).getChinascore() + list.get(i).getMathscore() + list.get(i).getEnglishscore() + list.get(i).getPhyscore()) { student = list.get(i); list.set(i, list.get(left)); list.set(left, student); } } left++; for (int i = right - 1; i >= left; i--) { if (list.get(right).getChinascore() + list.get(right).getMathscore() + list.get(right).getEnglishscore() + list.get(right).getPhyscore() > list.get(i).getChinascore() + list.get(i).getMathscore() + list.get(i).getEnglishscore() + list.get(i).getPhyscore()) { { student = list.get(i); list.set(i, list.get(right)); list.set(right, student); } } right--; } } return list; } //希尔排序 public void shellSort () { List<students> list = database.getStudentsList(); students student = null; students student1 = null; int j; for (int gap = list.size() / 2; gap > 0; gap /= 2) { for (int i = gap; i < list.size(); i++) { student = list.get(i); int tmp = student.getChinascore() + student.getMathscore() + student.getEnglishscore() + student.getPhyscore(); for (j = i; j >= gap && tmp > list.get(j - gap).getChinascore() + list.get(j - gap).getMathscore() + list.get(j - gap).getEnglishscore() + list.get(j - gap).getPhyscore(); j -= gap) { list.set(j, list.get(j - gap)); } list.set(j, student); } } } //快速排序 public void quickSort1 ( int left, int right){ List<students> studentsList = database.getStudentsList(); if (left < right) { int i = left, j = right; students student = studentsList.get(left); int x = student.getChinascore() + student.getMathscore() + student.getEnglishscore() + student.getPhyscore(); while (i < j) { while ((i < j) && (studentsList.get(j).getChinascore() + studentsList.get(j).getMathscore() + studentsList.get(j).getEnglishscore() + studentsList.get(j).getPhyscore()) < x) { j--; } if (i < j) { studentsList.set(i, studentsList.get(j)); i++; } while ((i < j) && (studentsList.get(i).getChinascore() + studentsList.get(i).getMathscore() + studentsList.get(i).getEnglishscore() + studentsList.get(i).getPhyscore() > x)) { i++; } if (i < j) { studentsList.set(j, studentsList.get(i)); j--; } } studentsList.set(i, student); quickSort1(left, i - 1); quickSort1(i + 1, right); } } //堆排序 //移除位在第一个数据的根节点,并做最大堆调整的递归运算 public List<students> heapSort(List<students> studentList){ List<students> list=studentList; int len = list.size(); buildMaxHeap(list, len); for (int i = len - 1; i > 0; i--) { swap(list, 0, i); len--; heapify(list, 0, len); } return list; } //将堆中的所有数据重新排序堆排序(HeapSort) private void buildMaxHeap(List<students> studentList, int len) { for (int i = (int) Math.floor(len / 2); i >= 0; i--) { heapify(studentList, i, len); } } private void heapify(List<students> studentList, int i, int len) { int left = 2 * i + 1; int right = 2 * i + 2; int largest = i; if (left < len && studentList.get(left).getChinascore() + studentList.get(left).getMathscore() + studentList.get(left).getEnglishscore() + studentList.get(left).getPhyscore()< studentList.get(largest).getChinascore() + studentList.get(largest).getMathscore() + studentList.get(largest).getEnglishscore() + studentList.get(largest).getPhyscore()) { largest = left; } if (right < len && studentList.get(right).getChinascore() + studentList.get(right).getMathscore() + studentList.get(right).getEnglishscore() + studentList.get(right).getPhyscore()< studentList.get(largest).getChinascore() + studentList.get(largest).getMathscore() + studentList.get(largest).getEnglishscore() + studentList.get(largest).getPhyscore()) { largest = right; } if (largest != i) { swap(studentList, i, largest); heapify(studentList, largest, len); } } private void swap(List<students> studentList, int i, int j) { students student=studentList.get(i); studentList.set(i,studentList.get(j)); studentList.set(j,student); } }
service
import java.util.Scanner; public class service { private studentdao studentdao; ; private database database; public service(database dataBase) { studentdao = new studentdao(dataBase); this.database = dataBase; } public void start() { Scanner scanner = new Scanner(System.in); System.out.println("1.增加学生信息"); System.out.println("2.浏览学生信息"); System.out.println("3.修改学生成绩"); System.out.println("4.排序学生成绩"); System.out.println("5.学生信息查询"); int choice = scanner.nextInt(); switch (choice) { case 1: add(); break; case 2: studentdao.print(); System.out.println("是否回到主界面0.回到1.不会"); int k=scanner.nextInt(); if(k==0) { start(); } break; case 3: changeit();break; case 4: rank(); break; case 5: search();break; } } //选择排序方式 public void rank(){ System.out.println("1.希尔排序"); System.out.println("2.冒泡排序"); System.out.println("3.快速排序"); System.out.println("4.堆排序"); System.out.println("输入0返回菜单"); Scanner scanner = new Scanner(System.in); int a=scanner.nextInt(); switch (a){ case 1: studentdao.shellSort(); studentdao.print(); System.out.println("是否回到主界面0.回到1.不会"); int p=scanner.nextInt(); if(p==0) { start(); } break; case 2: studentdao.bub(database.getStudentsList()); studentdao.print(); System.out.println("是否回到主界面0.回到1.不会"); int k=scanner.nextInt(); if(k==0) { start(); } break; case 3: studentdao.quickSort1(0,database.getStudentsList().size()-1); studentdao.print(); System.out.println("是否回到主界面0.回到1.不会"); int o=scanner.nextInt(); if(o==0) { start(); } break; case 4: studentdao.heapSort(database.getStudentsList()); studentdao.print(); System.out.println("是否回到主界面0.回到1.不会"); int k1=scanner.nextInt(); if(k1==0) { start(); } break; case 0:start(); break; } } //查找学生信息 public void search(){ studentdao.searchstudent(); Scanner scanner=new Scanner(System.in); System.out.println("是否回到主界面0.回到1.不会"); int k=scanner.nextInt(); if(k==0) { start(); } } //更改学生信息 public void changeit(){ studentdao.changescore(); System.out.println("是否回到主界面0.回到1.不会"); Scanner scanner=new Scanner(System.in); int k=scanner.nextInt(); if(k==0) { start(); } } //增加学生 public void add(){ studentdao.add(); System.out.println("是否回到主界面0.回到1.不会"); Scanner scanner=new Scanner(System.in); int k=scanner.nextInt(); if(k==0) { start(); } } }
text
public class text { public static void main(String[]args){ database database = new database(); service studentsSer=new service(database); studentsSer.start(); } }
The above is the detailed content of How to implement a simple student performance file management system in Java?. For more information, please follow other related articles on the PHP Chinese website!