java单链表成绩表_java实现学生成绩管理系统-单链表形式

这是一个用Java编写的学生成绩管理系统,使用单链表存储学生信息。系统支持添加、删除、查找学生,修改成绩,以及查看成绩排名和统计分析。
摘要由CSDN通过智能技术生成

package labReport;

import java.util.Scanner;

public class StudentInformation {

public String name = new String();

public long stuId = 0L;

public String lesson_1 = new String();

public String lesson_2 = new String();

public float scoreOfLesson_1 = 0f;

public float scoreOfLesson_2 = 0f;

public float sum = 0f;

public StudentInformation next = null;;

public StudentInformation(String name, long stuId, String lesson_1, String lesson_2, float scoreOfLesson_1, float scoreOfLesson_2){

this.lesson_1 = lesson_1;

this.lesson_2 = lesson_2;

this.name = name;

this.scoreOfLesson_1 = scoreOfLesson_1;

this.scoreOfLesson_2 = scoreOfLesson_2;

this.stuId = stuId;

this.sum = this.scoreOfLesson_1 + this.scoreOfLesson_2;

}

public StudentInformation(Scanner input){

this(input.next(), input.nextLong(), null, null, input.nextFloat(), input.nextFloat());

}

}

package labReport;

import java.util.Scanner;

public class StudentList {

public StudentInformation head = null;

private Scanner input = new Scanner(System.in);

public float sumLesson_1 = 0f, sumLesson_2 = 0f;

public StudentInformation maxStuSc_1, minStuSc_1;

public StudentInformation minStuSc_2, maxStuSc_2;

public StudentList(){

head = new StudentInformation(null, 0, null, null, 0, 0);

}

public StudentList(int lenght){

this();

int i = 0;

for(i = 0; i < lenght; i++)

insert();

}

public void change(long id){

float newScore_1 = 0f, newScore_2 = 0f;

StudentInformation p = head;

while(p != null){

if(p.stuId == id){

System.out.println("\n请输入学生的成绩:\t科目一\t科目二");

while(! input.hasNextFloat()){

input.next();

System.out.println("\n非法输入,请重新输入!");

System.out.println("\n请输入学生的成绩:\t科目一\t科目二");

}

newScore_1 = input.nextFloat();

while(! input.hasNextFloat()){

input.next();

System.out.println("\n非法输入,请重新输入!");

System.out.println("\n请输入学生的成绩:\t科目一\t科目二");

}

newScore_2 = input.nextFloat();

p.scoreOfLesson_1 = newScore_1;

p.scoreOfLesson_2 = newScore_2;

}

p = p.next;

}

}

public void insert() {//插入结点

StudentInformation p = head;

StudentInformation s = new StudentInformation(input);

s.next = p.next;

p.next = s;

}

public void remove(long id) throws Exception{//删除结点

StudentInformation p = head.next;

int j = -1;

while(p.next != null && j < lenght() - 1){

if(p.stuId == id)

break;

p = p.next;

j++;

}

if(j > lenght() || p == null){

throw new Exception("删除位置不合法");

}

p.next = p.next.next;

}

public int lenght() {//计算链表长度

int lenght = 0;

StudentInformation p = head.next;

while(p != null){

lenght++;

p = p.next;

}

return lenght;

}

public void rank(){//排序

StudentInformation p, q, snap1, snap2;

while(true){

int judge = 0;

p = head;

q = p.next;

while(p.next != null && q.next != null){

if(p.next.sum < q.next.sum){

judge = 1;

snap1 = p.next;

snap2 = q.next;

p.next = snap2;

snap1.next = snap1.next.next;

snap2.next = snap1;

}

if(q.next == null || p.next == null)

break;

p = p.next;

q = q.next;

}

if(judge == 0)

break;

}

}

public void findStudent(long id) throws Exception{//寻找某位学生

StudentInformation p = head.next;

while(p != null && p.stuId != id)

p = p.next;

if(p == null){

throw new Exception("您所寻找的位置不存在!");

}

System.out.println("学生姓名:" + p.name + "\t" + head.lesson_1 + "的成绩:" + (int)(p.scoreOfLesson_1 * 10) / 10.0

+ "\t" + head.lesson_2 + "的成绩:" + (int)(p.scoreOfLesson_2 * 10) / 10.0);

}

public void check(){//输出方法

StudentInformation p = head.next;

System.out.println("学生姓名\t学号\t科目一\t"

+ "成绩\t科目二\t成绩\t总分");

while(p != null){

System.out.println(p.name + "\t" + p.stuId + "\t" + head.lesson_1 + "\t"

+ (int)(p.scoreOfLesson_1 * 10) / 10.0 + "\t" + head.lesson_2 +

"\t" + (int)(p.scoreOfLesson_2 * 10) / 10.0 + "\t" + (int)(p.sum * 10) / 10.0);

p = p.next;

}

}

public void statistics(){

StudentInformation p = head.next;

float minScoreOfLesson_2 = 100f, minScoreOfLesson_1 = 100f;

float maxScoreOfLesson_2 = 0f, maxScoreOfLesson_1 = 0f;

while(p != null){

sumLesson_1 += p.scoreOfLesson_1;

sumLesson_2 += p.scoreOfLesson_2;

minStuSc_1 = minScoreOfLesson_1 < p.scoreOfLesson_1 ? minStuSc_1 : p;

maxStuSc_1 = maxScoreOfLesson_1 > p.scoreOfLesson_1 ? maxStuSc_1 : p;

maxStuSc_2 = maxScoreOfLesson_2 > p.scoreOfLesson_2 ? maxStuSc_2 : p;

minStuSc_2 = minScoreOfLesson_2 < p.scoreOfLesson_2 ? minStuSc_2 : p;

minScoreOfLesson_1 = minStuSc_1.scoreOfLesson_1;

minScoreOfLesson_2 = minStuSc_2.scoreOfLesson_2;

maxScoreOfLesson_1 = maxStuSc_1.scoreOfLesson_1;

maxScoreOfLesson_2 = maxStuSc_2.scoreOfLesson_2;

p = p.next;

}

System.out.println("科目一\n最高分\t姓名\t学号\n最低分\t姓名\t学号\t\n科目平均分");

System.out.println("" + maxStuSc_1.scoreOfLesson_1 + "\t" + maxStuSc_1.name + "\t" + maxStuSc_1.stuId + "\n" +

minStuSc_1.scoreOfLesson_1 + "\t" + minStuSc_1.name + "\t" + minStuSc_1.stuId);

System.out.println((int)((sumLesson_1 / lenght()) * 10) / 10.0);

System.out.println("科目二\n最高分\t姓名\t学号\n最低分\t姓名\t学号\t\n科目平均分");

System.out.println(maxStuSc_2.scoreOfLesson_2 + "\t" + maxStuSc_2.name + "\t" + maxStuSc_2.stuId + "\n" +

minStuSc_2.scoreOfLesson_2 + "\t" + minStuSc_2.name + "\t" + minStuSc_2.stuId);

System.out.println((int)((sumLesson_2 / lenght()) * 10) / 10.0);

}

}

package labReport;

import java.util.Scanner;

public class TestReport {

static{

System.out.println("欢迎使用学生管理系统(垃圾版)!");

System.out.println("请先完成一个成绩表格的初始化,谢谢合作!");

System.out.print("请输入需要统计成绩的两个科目名称:");

}

public static void main(String[] args){

StudentList list = new StudentList();

Scanner input = new Scanner(System.in);

int capita = 0;//初始人数

int i = 0;

list.head.lesson_1 = input.next();

list.head.lesson_2 = input.next();

System.out.println("请输入成绩统计初始人数!");

while(! input.hasNextInt()){

input.next();

System.out.println("非法输入,请重新输入:");

System.out.println("请输入成绩统计初始人数!");

}

capita = input.nextInt();

System.out.println("请按顺序输入学生的\t姓名\t学号\t" + list.head.lesson_1

+ "的成绩 \t" + list.head.lesson_2 + "的成绩");

for(i = 0; i < capita; i++)

list.insert();

menu(list);

input.close();

}

@SuppressWarnings("resource")

public static void menu(StudentList list){

Scanner input = new Scanner(System.in);

while(true){

System.out.println("现在进行操作选择!");

System.out.println("1、增加学生成员\t2、删除已有学生\t3、查找已有成员\t4、"

+ "修改已有学生成绩\t5、查看学生排名列表\t6、查看学生数据分析\t7、退出");

while(! input.hasNextInt()){

input.next();

System.out.println("非法输入,请重新输入!");

System.out.println("1、增加学生成员\t2、删除已有学生\t3、查找已有成员\t4、"

+ "修改已有学生成绩\t5、查看学生排名列表\t6、查看学生数据分析\t7、退出");

}

switch(input.nextInt()){

case 1: System.out.println("请按顺序输入学生的\t姓名\t学号\t" + list.head.lesson_1 + "的成绩\t" + list.head.lesson_2 + "的成绩");

list.insert();

System.out.println("操作成功!");

break;

case 2:

System.out.println("请输入要删除的学生成员学号!");

try {

while(! input.hasNextInt()){

input.next();

System.out.println("非法输入,请重新输入!");

}

list.remove(input.nextLong());

} catch (Exception e) {

e.printStackTrace();

}

System.out.println("操作成功!");

break;

case 3:

System.out.println("请输入需查找的学生成员的学号!");

try {

while(! input.hasNextInt()){

input.next();

System.out.println("非法输入,请重新输入!");

}

list.findStudent(input.nextLong());

} catch (Exception e) {

e.printStackTrace();

}

System.out.println("操作成功!");

break;

case 4:

System.out.println("请输入要修改成绩的学生的学号!");

while(! input.hasNextInt()){

input.next();

System.out.println("非法输入,请重新输入!");

}

list.change(input.nextLong());

System.out.println("操作成功!");

break;

case 5:

list.rank();

list.check();

System.out.println("操作成功!");

break;

case 6:

list.statistics();

System.out.println("操作成功!");

break;

case 7: System.out.println("感谢您本次对本产品的使用!");

System.exit(0);

break;

default:

try {

System.out.println("非法选项!\n请重新进入菜单选择");

Thread.sleep(10000);

} catch (InterruptedException e) {

e.printStackTrace();

}

break;

}

}

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值