题目要求:
代码:
Student.java:
public class Student {private long id;//学号
private String name;//姓名
private double math;//应用数学成绩
private double English;//大学英语成绩
private double Java;//java成绩
private double computer;//计算机应用基础
private double average; //平均分
private int n; //总人数
public double getAverage() {return average;
}
public void setAverage(double average) {this.average = average;
}
public Student(int n,long id, String name, double math, double english, double java, double computer, double average) {this.n = n;
this.id = id;
this.name = name;
this.math = math;
this.English = english;
this.Java = java;
this.computer = computer;
this.average=average;
}
public Student() {}
public int getNum() {return n;
}
public void setNum(int n) {this.n = n;
}
public long getId() {return id;
}
public void setId(long id) {this.id = id;
}
public String getName() {return name;
}
public void setName(String name) {this.name = name;
}
public double getMath() {return math;
}
public void setMath(double math) {this.math = math;
}
public double getEnglish() {return English;
}
public void setEnglish(double English) {this.English = English;
}
public double getJava() {return Java;
}
public void setJava(double Java) {this.Java = Java;
}
public double getComputer() {return computer;
}
public void setComputer(double computer) {this.computer = computer;
}
public double getAvg(Student student) {return ( (student.getMath() + student.getEnglish() + student.getJava() + student.getComputer())/4);
}
public void setAvg(double average) {this.average=average;
}
}
StudentApplication.java:
public class StudentApplication {public static Scanner scanner = new Scanner(System.in);
public static ArrayListstudents = new ArrayList<>();
public static void main(String[] args) {Student student = new Student();
StudentManage sm=new StudentManage();
while(true){ int menuSelect=StudentManage.getMenu();
switch (menuSelect){ case 1://输入学生相关信息
sm.addStudent(students);
break;
case 2://2按平均分降序排列
sm.sortStudent(students);
break;
case 3:// 3显示所有成绩
sm.showAllStudent(students);
break;
case 4: //4输入查询个人成绩
sm.searchStudent(students);
break;
case 5://5显示各科平均分,最高分,最低分
sm.averageScore(students);
break;
case 6://6退出成绩管理系统
System.out.println("即将退出成绩管理系统");
System.exit(0);
default:
System.out.println("请重新输入");
break;
}
}
}
}
StudentManage.java:
public class StudentManage {private static Scanner sc=new Scanner(System.in);
//得到菜单
public static int getMenu(){System.out.println("----------学生成绩管理系统----------");
System.out.println(" 1输入学生相关信息");
System.out.println(" 2按平均分降序排列");
System.out.println(" 3显示所有成绩");
System.out.println(" 4输入查询个人成绩");
System.out.println(" 5显示各科平均分,最高分,最低分");
System.out.println(" 6退出成绩管理系统");
System.out.println("----------学生成绩管理系统----------");
System.out.println("请选择菜单:");
int select=StudentManage.sc.nextInt();
return select;
}
//添加学生
public void addStudent(ArrayListstudents){Student student=new Student();
System.out.println("请输入学生的学号");
student.setId(sc.nextLong());
System.out.println("请输入学生的姓名");
student.setName(sc.next());
System.out.println("请输入学生的应用数学成绩");
student.setMath(sc.nextDouble());
System.out.println("请输入学生的大学英语成绩");
student.setEnglish(sc.nextDouble());
System.out.println("请输入学生的java程序设计成绩");
student.setJava(sc.nextDouble());
System.out.println("请输入学生的计算机应用基础成绩");
student.setComputer(sc.nextDouble());
double avg = student.getAvg(student);
student.setAverage(avg);
students.add(student);
// 提示信息
System.out.println("添加成功");
}
//查询学生
public void searchStudent(ArrayListstudents){if (students.size() == 0) {System.out.println("当前无数据,请添加后重试");
} else {System.out.println("请输入要查找学生的学号:");
long id = sc.nextLong();
int flag = -1;
Student student = new Student();
// 查找对应学号,找到就退出
for (int i = 0; i< students.size(); i++) {student = students.get(i);
if (student.getId() == id) {flag = i;
break;
}
}
if (flag == -1) {System.out.println("未找到对应学号的学生,请确认后重新输入!");
} else {System.out.println("对应学号的学生成绩如下:");
System.out.println("学号\t\t\t姓名\t\t数学\t\t英语\t\tJava\t\tcomputer\t\t平均分\t\t");
System.out.format("%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n", student.getId(), student.getName(), student.getMath(), student.getEnglish(), student.getJava(),student.getComputer(), student.getAvg(student));
System.out.println("查找信息成功!");
}
}
}
//按平均分排降序
public void sortStudent(ArrayListstudents){if (students.isEmpty()) {System.out.println("当前无数据,请添加后重试");
} else {for (int i = 0; i< students.size() - 1; i++) {if (students.get(i).getAvg(students.get(i))< students.get(i + 1).getAvg(students.get(i + 1))) {Student tmp = students.get(i);
students.set(i, students.get(i + 1));
students.set(i + 1, tmp);
}
}
System.out.println("排序后的学生成绩");
System.out.println("学号\t\t姓名\t\t数学\t\t英语\t\tJava\t\t计算机\t\t平均分");
for (Student student : students) {System.out.format("%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t\n", student.getId(), student.getName(), student.getMath(), student.getEnglish(), student.getJava() ,student.getComputer(), student.getAvg(student));
}
}
}
//显示所有成绩
public void showAllStudent(ArrayListstudents){if (students.isEmpty()) {System.out.println("当前无数据,请先添加数据");
} else {System.out.println("----------所有学生成绩如下----------");
System.out.println("学号\t\t姓名\t\t数学\t\t英语\t\tJava\t\t计算机\t\t平均分");
for (Student student : students) {System.out.format("%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n", student.getId(), student.getName(), student.getMath(), student.getEnglish(), student.getJava(),student.getComputer(), student.getAvg(student));
}
}
}
//各科平均分,最高分,最低分
public void averageScore(ArrayListstudents){int n = students.size();
double max1 = 0;
double min1 = students.get(0).getMath();;
double sum1 = 0;
for (int i = 0; i< n; i++) { sum1 = sum1 + students.get(i).getMath();
if (students.get(i).getMath() >max1) { max1 = students.get(i).getMath();
}
if (students.get(i).getMath()< min1) {min1 = students.get(i).getMath();
}
}
System.out.println("应用数学的平均成绩="+sum1/n+" 最高成绩="+max1+" 最低成绩="+min1);
double max2 = 0;
double min2 = students.get(0).getEnglish();;
double sum2 = 0;
for (int i = 0; i< n; i++) { sum2 = sum2 + students.get(i).getEnglish();
if (students.get(i).getEnglish() >max2) {max2 = students.get(i).getEnglish();
}
if (students.get(i).getEnglish()<= min2) {min2 = students.get(i).getEnglish();
}
}
System.out.println("大学英语的平均成绩="+sum2/n+" 最高成绩="+max2+" 最低成绩="+min2);
double max3 = 0;
double min3 = students.get(0).getJava();;
double sum3 = 0;
for (int i = 0; i< n; i++) { sum3 = sum3 + students.get(i).getJava();
if (students.get(i).getJava() >max3) { max3 = students.get(i).getJava();
}
if (students.get(i).getJava()<= min3) {min3 = students.get(i).getJava();
}
}
System.out.println("Java的平均成绩="+sum3/n+" 最高成绩="+max3+" 最低成绩="+min3);
double max4 = 0;
double min4 = students.get(0).getComputer();;
double sum4 = 0;
for (int i = 0; i< n; i++) { sum4 = sum4 + students.get(i).getComputer();
if (students.get(i).getEnglish() >max4) { max4 = students.get(i).getComputer();
}
if (students.get(i).getComputer()<= min4) {min4 = students.get(i).getComputer();
}
}
System.out.println("计算机应用基础的平均成绩="+sum4/n+" 最高成绩="+max4+" 最低成绩="+min4);
}
}
运行主界面:
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
当前题目:Java课设-学生成绩管理系统-创新互联
标题网址:https://www.cdcxhl.com/article36/dspcpg.html
成都网站建设公司_创新互联,为您提供虚拟主机、网站导航、标签优化、品牌网站建设、网站营销、网站设计
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联