写了一天,非常得没有效率,比较粗糙,注释不太丰富,但应该足以理解。强调:如有雷同,肯定被我参考了。不会写博客,以后会学习,这次就这样了。io参考链接:https://www.cnblogs.com/perfectzk/p/5575983.html题目是这样的:

##实验任务
学生信息录入,信息包括学号、姓名、专业、四门课成绩、总分、名次;
系统可对学生信息浏览、增加、删除和修改;
按学生成绩确定名次及信息输出,双向冒泡排序、希尔排序、快速排序、堆排序。
要求可对学生信息查询,根据学号或姓名进行查找;
信息修改仅可修改四门课成绩;
文件存取学生信息。

##工具:IDEA java jdk 1.8
##大体思路:首先创建一个Student类,生成构造方法还有getter和setter,继承Serializable接口,原因:一个对象序列化的接口,一个类只有实现了Serializable接口,它的对象才能被序列化。为了把对象存到文件里。第三个类调用main方法创建第二个类的实例,调用start()方法,就这个作用。第二个类做了很多事情,都是任务里的,不多不少,没有注册登陆功能。详细内容看代码。

##总结: 封装等于没封装(变量可以随便改,改不了删了再建不就完事了),这个没能力解决。io的操作copy来的,不太懂。if-else括号没加,浪费很长时间测试。
代码块相似度高,可优化空间还很大。快排还能优化,1.选几个数取中间数为标杆值 2.列表少于十个用插入排序,还有
其他办法我也不知道。对对象排序真烦,不如compator方便。其他还行。。。
##以下是代码(很多就不分了,分开更难找):
//Student类


public class Student implements Serializable {private int studentNumber;private String name;private String profession;private double  algorithmScore;private   double  mathsScore;private double  politicsScore;private   double  englishScore;private   double  scoreSum;private   int   ranking;public Student() {}public Student(int studentNumber, String name, String profession, double algorithmScore, double mathsScore, double politicsScore, double englishScore, double scoreSum, int ranking) {this.studentNumber = studentNumber;this.name = name;this.profession = profession;this.algorithmScore = algorithmScore;this.mathsScore = mathsScore;this.politicsScore = politicsScore;this.englishScore = englishScore;this.scoreSum = scoreSum;this.ranking = ranking;}public void setScoreSum(double scoreSum) {this.scoreSum = scoreSum;}public void setRanking(int ranking) {this.ranking = ranking;}public int getStudentNumber() {return studentNumber;}public String getName() {return name;}public String getProfession() {return profession;}public double getAlgorithmScore() {return algorithmScore;}public double getMathsScore() {return mathsScore;}public double getPoliticsScore() {return politicsScore;}public double getEnglishScore() {return englishScore;}public double getScoreSum() {return scoreSum;}public int getRanking() {return ranking;}public void setAlgorithmScore(double algorithmScore) {this.algorithmScore = algorithmScore;}public void setMathsScore(double mathsScore) {this.mathsScore = mathsScore;}public void setPoliticsScore(double politicsScore) {this.politicsScore = politicsScore;}public void setEnglishScore(double englishScore) {this.englishScore = englishScore;}public String toString() {return "studentNumber: "+ studentNumber+ "\tname: "+ name+ "\tprofession: "+ profession+"\talgorithmScore: "+ algorithmScore+"\tmathsScore: "+mathsScore+"\tpoliticsScore: "+ politicsScore+"\tenglishScore: "+englishScore+"\tscoreSum: "+scoreSum+"\tranking: "+ranking;}private static final long serialVersionUID = 1L;
}**//**Main类****
``public class Main {public static void main(String[] args) {StudentManagement studentManagement=new StudentManagement();studentManagement.start();}
}`
**//StudentManagement类**
import java.io.*;
import java.util.*;public class StudentManagement {private static File DB = new File("students.db");private static List<Student> studentList = null;private Scanner scanner = new Scanner(System.in);private Random random=new Random();@SuppressWarnings("unchecked")/*** 初始化对象列表,从文件(数据库)中读取信息*/private static void initStudentList() {if (DB.exists()) {FileInputStream fi = null;ObjectInputStream oi = null;try {fi = new FileInputStream(DB);oi = new ObjectInputStream(fi);Object obj = oi.readObject();fi.close();oi.close();if (obj instanceof List)studentList = (List<Student>) obj;} catch (Exception e) {e.printStackTrace();}}if (studentList == null)studentList = new ArrayList<>();}private static void save() {if (studentList == null)return;if (!DB.exists())try {DB.createNewFile();} catch (Exception e) {e.printStackTrace();}FileOutputStream fo;try {fo = new FileOutputStream(DB);ObjectOutputStream oo = new ObjectOutputStream(fo);oo.writeObject(studentList);fo.close();oo.close();} catch (Exception e) {e.printStackTrace();}}static {initStudentList();}/***    开始菜单*/public void start() {System.out.println("1. 登录");System.out.println("2. 退出系统");System.out.println("请选择:");int chooice = scanner.nextInt();switch (chooice) {case 1://登录mainMenu();break;case 2://退出System.out.println("退出了系统!");break;default:System.out.println("无效的选项,请重新输入!");start();}}/*** 主菜单*/public void mainMenu() {System.out.println("0.返回上一层菜单");System.out.println("1.成绩查询");System.out.println("2.后台管理");System.out.println("请输入序号:");int  num=scanner.nextInt();switch (num) {case 0:start();break;case 1:search();break;case 2:studentManage();break;default:System.out.println("无效的选项,请重新输入!");mainMenu();}}/*** 成绩查询*/public void search() {//显示查询菜单System.out.println("0.返回上一层菜单");System.out.println("1.学号查询");System.out.println("2.姓名查询");System.out.println("3.学生成绩总览(降序)");System.out.println("请输入序号:");int num = scanner.nextInt();switch (num) {case 0:mainMenu();break;case 1:studentNumberSearch();break;case 2:nameSearch();break;case 3:studentsRanking();break;default:System.out.println("无效的选项,请重新输入!");search();}}/*** 学号查询*/public void studentNumberSearch(){System.out.println("请输入学号:");int  studentNumber1=scanner.nextInt();Student  s= findByNumber(studentNumber1);if (s!=null){System.out.println(s);}else {System.out.println("没有这个学号!");}System.out.println("输入0返回上一层菜单,其他任意键继续");String result = scanner.next();if (result.equals("0")) {search();} else studentNumberSearch();}/*** 姓名查询*/public void nameSearch(){System.out.println("请输入姓名:");String name1 = scanner.next();Student  s=findByName(name1);if (s!=null){System.out.println(s);}else {System.out.println("没有这个姓名!");}System.out.println("输入0返回上一层菜单,其他任意键继续");String result = scanner.next();if (result.equals("0")) {search();} else nameSearch();}/***  学生成绩总览*/public void studentsRanking(){System.out.println("0.返回上一层菜单");System.out.println("1.冒泡排序");System.out.println("2.希尔排序");System.out.println("3.快速排序");System.out.println("4.堆排序");System.out.println("请输入序号:");int num = scanner.nextInt();switch (num) {case 0:search();break;case 1:bubbleSort();break;case 2:shellSort();break;case 3:quickSort(0,studentList.size()-1);break;case 4:heapSort();break;default:System.out.println("无效的选项,请重新输入!");studentsRanking();}rankingCorrect();save();printList();studentsRanking();}/*** 后台管理*/public void studentManage() {System.out.println("0.返回上一层菜单");System.out.println("1.新增学生");System.out.println("2.修改成绩");System.out.println("3.删除学生");//显示新增学生、修改成绩、删除学生菜单System.out.println("请输入序号:");int num = scanner.nextInt();switch (num) {case 0:mainMenu();break;case 1:addStudent();break;case 2:modifyScore();break;case 3:deleteStudent();break;default:System.out.println("无效的选项,请重新输入!");search();}}/*** 新增学生*/public void  addStudent(){System.out.println("请输入学号:");int  number1=scanner.nextInt();System.out.println("请输入姓名:");String name1=scanner.next();System.out.println("请输入专业:");String  profession1=scanner.next();System.out.println("请输入算法成绩:");double  algorithmScore1=scanner.nextDouble();System.out.println("请输入数学成绩:");double  mathsScore1=scanner.nextDouble();System.out.println("请输入政治成绩:");double politicsScore1=scanner.nextDouble();System.out.println("请输入英语成绩:");double englishScore1=scanner.nextDouble();Double  scoreSum1=algorithmScore1+mathsScore1+politicsScore1+englishScore1;System.out.println("请输入排名:");int ranking1  =scanner.nextInt();studentList.add(new Student(number1,name1,profession1,algorithmScore1,mathsScore1,politicsScore1,englishScore1,scoreSum1,ranking1));shellSort();rankingCorrect();save();System.out.println("添加成功!");System.out.println("输入0返回上一层菜单,其他任意键继续");String result = scanner.next();if (result.equals("0")) {studentManage();} else addStudent();}/*** 修改四门课成绩*/public void modifyScore() {System.out.println("0.返回上一层菜单");System.out.println("1.学号查询");System.out.println("2.姓名查询");System.out.println("请输入:");Student s=new Student();int num1 = scanner.nextInt();switch (num1) {case 0:studentManage();break;case 1:System.out.println("请输入学号:");int  studentNumber1=scanner.nextInt();Student s1= findByNumber(studentNumber1);if (s1!=null){s=s1;}else {System.out.println("没有这个学号!");modifyScore();}break;case 2:System.out.println("请输入姓名:");String name1 = scanner.next();Student s2=findByName(name1);if (s2!=null){s=s2;}else {System.out.println("没有这个姓名!");modifyScore();}break;default:System.out.println("无效的选项,请重新输入!");modifyScore();}System.out.println("0.不想改了");System.out.println("1.修改算法成绩");System.out.println("2.修改数学成绩");System.out.println("3.修改政治成绩");System.out.println("4.修改英语成绩");System.out.println("请输入序号:");int num2=scanner.nextInt();switch (num2) {case 0:studentManage();break;case 1:System.out.println("请输入修改的成绩:");double score1 = scanner.nextDouble();s.setAlgorithmScore(score1);s.setScoreSum(score1+s.getMathsScore()+s.getPoliticsScore()+s.getEnglishScore());shellSort();rankingCorrect();save();System.out.println("修改成功!");break;case 2:System.out.println("请输入修改的成绩:");double score2 = scanner.nextDouble();s.setMathsScore(score2);s.setScoreSum(score2+s.getAlgorithmScore()+s.getPoliticsScore()+s.getEnglishScore());shellSort();rankingCorrect();save();System.out.println("修改成功!");break;case 3:System.out.println("请输入修改的成绩:");double score3 = scanner.nextDouble();s.setPoliticsScore(score3);s.setScoreSum(score3+s.getAlgorithmScore()+s.getMathsScore()+s.getEnglishScore());shellSort();rankingCorrect();save();System.out.println("修改成功!");break;case 4:System.out.println("请输入修改的成绩:");double score4 = scanner.nextDouble();s.setEnglishScore(score4);s.setScoreSum(score4+s.getAlgorithmScore()+s.getPoliticsScore()+s.getMathsScore());shellSort();rankingCorrect();save();System.out.println("修改成功!");break;default:System.out.println("无效的选项,请重新输入!");modifyScore();}System.out.println("输入0返回上一层菜单,其他任意键继续:");String  s1=scanner.next();if (s1.equals("0")) {studentManage();} else modifyScore();}/*** 删除学生*/public void deleteStudent() {System.out.println("0.返回上一层菜单");System.out.println("1.学号查询");System.out.println("2.姓名查询");System.out.println("请输入:");Student s=new Student();int num1 = scanner.nextInt();switch (num1) {case 0:studentManage();break;case 1:System.out.println("请输入学号:");int  studentNumber1=scanner.nextInt();Student s1= findByNumber(studentNumber1);if (s1!=null){s=s1;}else {System.out.println("没有这个学号!");deleteStudent();}break;case 2:System.out.println("请输入姓名:");String name1 = scanner.next();Student s2=findByName(name1);if (s2!=null){s=s2;}else {System.out.println("没有这个姓名!");deleteStudent();}break;default:System.out.println("无效的选项,请重新输入!");deleteStudent();}studentList.remove(s);shellSort();rankingCorrect();save();System.out.println("删除成功!");System.out.println("输入0返回上一层菜单,其他任意键继续:");String  s1=scanner.next();if (s1.equals("0")) {studentManage();} else deleteStudent();}public  Student  findByNumber(int studentNumber){Student s1=new Student();for (Student s:studentList) {if (s.getStudentNumber()==studentNumber)return s;}return s1;}public  Student findByName(String name){Student s1=new Student();for (Student s:studentList) {if (s.getName().equals(name))return s;}return  s1;}/*** 冒泡排序*/public void bubbleSort(){int n=studentList.size();if (n<2)  return;int work; //判断是否发生交换for (int i =n-1 ; i >0; i--) {work=0;for (int j = 0; j <i ; j++) {if (studentList.get(j).getScoreSum()<studentList.get(j+1).getScoreSum()){Student  tempj=studentList.get(j);studentList.set(j,studentList.get(j+1));studentList.set(j+1,tempj);work=1;}}if (work==0)  return;}}/*** 希尔排序*///对希尔排序中的单个组进行排序public void  groupSort(int n,int istart,int istep){Student itemp;//当前需要排序的对象int i;//需要排序对象的计数器int j;//插入排序时需要后移对象的计数器for (i = istart+istep;  i<n ; i=i+istep) {itemp=studentList.get(i);//待排序对象//从已排序的最右边开始,把小于当前排序的元素右移for (j= i-istep;  j>=0 ; j=j-istep) {if (studentList.get(j).getScoreSum()>=itemp.getScoreSum()) break;studentList.set(j+istep,studentList.get(j));}studentList.set(j+istep,itemp);}}public void shellSort(){int i,istep;//istep为步长(增量),每次减为原来的一半向下取整,最后一次为1int n=studentList.size();if (n<2) return;for (istep = n/2; istep >0 ; istep=istep/2) {for (i = 0;  i<istep ; i++) {groupSort(n,i,istep);}}}/*** 快速排序*/public void  quickSort(int left,int right){if (right-left+1<2) return;Student itemp=studentList.get(left);int ileft=left;//左下标int iright=right;//右下标int imoving=2;while (ileft<iright){if (imoving==2){if (studentList.get(iright).getScoreSum()<=itemp.getScoreSum()){iright--;continue;}studentList.set(ileft,studentList.get(iright));ileft++;imoving=1;continue;}if (imoving==1){if (studentList.get(ileft).getScoreSum()>=itemp.getScoreSum()){ileft++;continue;}studentList.set(iright,studentList.get(ileft));iright--;imoving=2;continue;}}studentList.set(ileft,itemp);quickSort(left,ileft-1);quickSort(ileft+1,right);}/*** 堆排序*/public void heapSort(){int i;int n=studentList.size();/**初始化堆,从最后一个父节点开始调整**/for(i=(n-1)/2;i>=0;i--)  heapify(i,n-1);for (i=n-1;i>0;i--){swap(0,i);heapify(0,i-1);}}public void heapify(int start,int end){int parent=start;int son=parent*2+1;while(son<=end){//采用循环实现heapifyif (son+1<=end&&studentList.get(son).getScoreSum()>studentList.get(son+1).getScoreSum())son++;if (studentList.get(parent).getScoreSum()<studentList.get(son).getScoreSum())return;swap(parent,son);parent=son;son=parent*2+1;}}public void swap(int i,int j){Student itemp=studentList.get(i);studentList.set(i,studentList.get(j));studentList.set(j,itemp);}public void printList(){for (Student s:studentList) {System.out.println(s.getRanking()+"\t" +s.getStudentNumber()+ "\t" + s.getName() + "\t" +s.getProfession()+ "\t" +s.getAlgorithmScore()+ "\t" +s.getMathsScore()+ "\t" +s.getPoliticsScore()+ "\t" +s.getEnglishScore()+ "\t" +s.getScoreSum());}}public void rankingCorrect() {for (int i = 0; i < studentList.size(); i++) {studentList.get(i).setRanking(i + 1);}}
}

#数据结构与算法 第一小题 学生成绩档案管理系统相关推荐

  1. 《数据结构课程实践》_01_学生成绩档案管理系统_准备工作

    01_学生成绩档案管理系统_准备工作 一.实验题目与要求 二.编程语言以及开发环境 三.实验思路 1. 思考初始化数据处理 2. 学生对象处理 3. 操作处理 4. 方法描述 四.预习小结 一.实验题 ...

  2. 《数据结构课程实践》_01_学生成绩档案管理系统_实现

    01_学生成绩档案管理系统_实现 一.实验题目 二.编程语言以及开发环境 三.源代码 1.学生类 2.自定义数据库类 3.数据操作类 4.总服务类 5. main类 四.运行结果 五.实验小结 一.实 ...

  3. 题目1:学生成绩档案管理系统(实验准备)

    数据结构课程实践系列 题目1:学生成绩档案管理系统(实验准备) 题目2:隐式图的搜索问题(A*算法解决八数码) 题目3:文本文件单词的检索与计数(实验准备) 文章目录 数据结构课程实践系列 题目1:学 ...

  4. 学生成绩档案管理系统(预习)

    学生成绩档案管理系统 实验任务 需求分析 开发环境 设计思路 相关算法 实验任务 1.学生信息录入,信息包括学号.姓名.专业.四门课成绩.总分.名次:系统可对学生信息浏览.增加.删除和修改: 2.按学 ...

  5. 学生成绩档案管理系统

    学生成绩档案管理系统 实验要求 实验设计 实验分析 初步分析 算法设计 快速排序 双向冒泡排序 堆排序 希尔排序 实验要求 • 学生信息录入,信息包括学号.姓名.专业.四门课成绩.总分.名次: • 系 ...

  6. 题目1:学生成绩档案管理系统(代码实现)

    文章目录 Database Accounts Accounts AccountsInOut Student Student StudentSys DAO AccountsDao StudentDao ...

  7. 学生成绩档案管理系统(准备+结果)

    文章目录 一.实验任务及其实现功能 需求分析 二.开发工具及编程语言 1.开发工具 编程语言 三.算法分析 1.双向冒泡排序 2.希尔排序 3.快速排序 4.堆排序 参考资料 四.源代码 Pojo D ...

  8. 数据结构和算法 第二小题 九宫重排(1)

    参考了csdn里的一篇文章(leetcode上没找到),他用C++写的, 双向bfs队列搜索.我把C++的代码改成了java,链接:https://blog.csdn.net/qq_45775045/ ...

  9. 数据结构和算法 | 第一部分第二课:小鸭子们去旅行

    作者 谢恩铭,公众号「程序员联盟」. 转载请注明出处. 原文:https://www.jianshu.com/p/31d14bd080d4 内容简介 引出算法复杂度的故事 两种算法 两种算法的对比 第 ...

最新文章

  1. android java style_Android 在Java代码中设置style属性--使用代码创建ProgressBar对象
  2. lua学习笔记之日期时间
  3. 26_练习2_用户搜索_初始化显示(静态页面)
  4. oracle分库分表原理_02. MyCat 的原理,应用场景,分库分表的思想
  5. python PyQt5 QtCore.QPointF类、QPointF类与QPoint类区别
  6. 编程类-----matlab基础语法复习(1)
  7. 人人都能学会的python编程教程(基础篇)完整版
  8. SAP gateway里一个控制缓存行为的开关 User parameter /UI2/PAGE_CACHE_OFF
  9. java 缓存ech_ehcache获取缓存空指针
  10. Safari 版本回退方法
  11. Chrome浏览器多开,亲测有效
  12. 蛋疼的strtok函数
  13. Spring Setter方法注入
  14. armv6、armv7、armv7s及arm64
  15. CityEngine学习资料——split分割
  16. PHP获取Opcode及C源码
  17. 快速使用 Docker 部署 Spring Boot 项目
  18. 批量替换Word中的表格为图片并保存
  19. 机器学习(线性模型)
  20. 基于MATLAB App Designer的串口RS485 Modbus上位机

热门文章

  1. jzoj 1307. Jail
  2. 使用BookMarkHub插件实现在不同浏览器之间进行书签同步
  3. Coredump-X: C++:std::terminate
  4. pytorch 中 混合精度训练(真香)
  5. HTML5 2D游戏引擎研发系列 第五章
  6. 动态域名解析服务器离线会引起什么_动态域名解析过程中可能出现的问题及解决方案...
  7. linux部署nestjs项目
  8. 设计一个长方体类Cuboid
  9. Using Memory Efficiently(Pro Android Apps Performance Optimization)
  10. PCB设计入门—学习记录