这篇文章主要为大家详细介绍了java控制台实现简单的学生管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了java控制台实现学生管理系统的具体代码,供大家参考,具体内容如下
编写一个学生成绩管理程序。学生的属性包括学号、姓名、年龄等。每个学生要学习若干课程,每门课程有平时成绩、期中考试成绩、实习成绩、期末考试成绩以及总评成绩等多个成绩,其中平时成绩的数目不定(因为不同课程的教师布置的平时作业数不同),而总评成绩是其它成绩的平均值。请先设计合理的对象容器类存放这些信息,然后设计程序完成以下功能:
1)列出某个学生的所有成绩;
2)列出某门课程每个学生的总评成绩,及所有学生总评成绩的总评分;
3)分区段统计某门课程的学生总评成绩,例如60 分以下的学生人数、60 至70 分的学生人数等。
Student类:
package homework032002;
import java.util.ArrayList;
public class Student {
private String name;
private String no;
private int age;
private ArrayList<Grade> Grade;
public ArrayList<Grade> getCourses() {
return Grade;
}
public void setCourses(ArrayList<Grade> Grade) {
this.Grade = Grade;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Student [name=" + name + ", no=" + no + ", age=" + age + ", course=" + Grade + "]";
}
public Student(String name, String no, int age, ArrayList<Grade> Grade) {
super();
this.name = name;
this.no = no;
this.age = age;
this.Grade = Grade;
}
public Student() {
super();
// TODO Auto-generated constructor stub
}
}
Function类:(功能封装在此类中):
package homework032002;
import homework032002.Grade;
import java.util.ArrayList;
public class Function {
//static ArrayList<Grade> arrayList = new ArrayList<>();
//static ArrayList<Student> arrayList2 = new ArrayList<>();
private ArrayList<Student> arrayList2;
public Function(ArrayList<Student> arrayList) {
super();
this.arrayList2 = arrayList;
}
//根据名字搜索该学生的成绩
public void show(String name) {
for (Student s : arrayList2) {
if(s.getName().equals(name)) {
ArrayList<Grade> course = s.getCourses();
System.out.println("该学生的成绩是:");
for(Grade grade : course) {
System.out.println(grade);
}
break;
}
}
}
//列出某门课程每个学生的总评成绩,及所有学生总评成绩的总评分
public void showOneSum(String courseName) {
double sumGrade = 0;
int num = 0;
for(Student student : arrayList2) {
ArrayList<Grade> grades = student.getCourses();
for(Grade grade : grades) {
if(courseName.equals(grade.getCourse())) {
num++;
sumGrade += grade.getSumGrade();
System.out.println(student.getName()+"的总评分是"+grade.getSumGrade());
}
}
}
System.out.println("所有学生的总评分是:"+sumGrade/num);
}
//分区段统计某门课程的学生总评成绩,例如60 分以下的学生人数、60 至70 分的学生人数等
public void selectGrade(String courseName) {
int down60 = 0;
int down60_70 = 0;
for(Student student : arrayList2) {
ArrayList<Grade> grades = student.getCourses();
for(Grade grade : grades) {
if(courseName.equals(grade.getCourse())) {
if(grade.getSumGrade() < 60) {
down60++;
}else if (grade.getSumGrade() > 60 || grade.getSumGrade() <70) {
down60_70++;
}
}
}
}
System.out.println("60分以下的有"+down60+"人");
System.out.println("60-70分以下的有"+down60_70+"人");
}
}
Grade类:(课程类)
package homework032002;
//每门课程有平时成绩、期中考试成绩、实习成绩、期末考试成绩以及总评成绩等多个成绩
public class Grade {
private String course;
private int dailyGrade;
private int midGrade;
private int doGrade;
private int endGrade;
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
public Grade(String course, int dailyGrade, int midGrade, int doGrade, int endGrade, double sumGrade) {
super();
this.course = course;
this.dailyGrade = dailyGrade;
this.midGrade = midGrade;
this.doGrade = doGrade;
this.endGrade = endGrade;
this.sumGrade = sumGrade;
}
public int getDailyGrade() {
return dailyGrade;
}
public void setDailyGrade(int dailyGrade) {
this.dailyGrade = dailyGrade;
}
private double sumGrade;
public int getMidGrade() {
return midGrade;
}
public void setMidGrade(int midGrade) {
this.midGrade = midGrade;
}
public int getDoGrade() {
return doGrade;
}
public void setDoGrade(int doGrade) {
this.doGrade = doGrade;
}
public int getEndGrade() {
return endGrade;
}
public void setEndGrade(int endGrade) {
this.endGrade = endGrade;
}
public double getSumGrade() {
return sumGrade;
}
public void setSumGrade(double sumGrade) {
this.sumGrade = sumGrade;
}
@Override
public String toString() {
return "Grade [course=" + course + ", dailyGrade=" + dailyGrade + ", midGrade=" + midGrade + ", doGrade="
+ doGrade + ", endGrade=" + endGrade + ", sumGrade=" + sumGrade + "]";
}
}
测试类:
package homework032002;
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
ArrayList<Student> students = new ArrayList<>();
ArrayList<Grade> grades = new ArrayList<>();
students.add(new Student("小明", "12", 13, grades));
grades.add(new Grade("高数", 50, 95, 45, 78, 76));
grades.add(new Grade("语文", 50, 95, 45, 78, 76));
grades.add(new Grade("英语", 50, 95, 45, 78, 76));
grades.add(new Grade("计算机", 50, 95, 45, 78, 76));
ArrayList<Grade> grades1 = new ArrayList<>();
students.add(new Student("小红", "12", 13, grades1));
grades1.add(new Grade("高数", 50, 95, 45, 78, 76));
grades1.add(new Grade("语文", 50, 95, 45, 78, 76));
grades1.add(new Grade("英语", 50, 95, 45, 78, 76));
grades1.add(new Grade("计算机", 50, 95, 45, 78, 76));
ArrayList<Grade> grades2 = new ArrayList<>();
students.add(new Student("小上", "12", 13, grades2));
grades2.add(new Grade("高数", 50, 95, 45, 78, 76));
grades2.add(new Grade("语文", 50, 95, 45, 78, 76));
grades2.add(new Grade("英语", 50, 95, 45, 78, 76));
grades2.add(new Grade("计算机", 50, 95, 45, 78, 76));
ArrayList<Grade> grades3 = new ArrayList<>();
students.add(new Student("小蓝", "12", 13, grades3));
grades3.add(new Grade("高数", 50, 95, 45, 78, 76));
grades3.add(new Grade("语文", 50, 95, 45, 78, 76));
grades3.add(new Grade("英语", 50, 95, 45, 78, 76));
grades3.add(new Grade("计算机", 50, 95, 45, 78, 76));
Function function = new Function(students);
function.show("小明");
function.showOneSum("计算机");
function.selectGrade("高数");
}}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
沃梦达教程
本文标题为:java控制台实现学生管理系统
基础教程推荐
猜你喜欢
- Java并发编程进阶之线程控制篇 2023-03-07
- java实现多人聊天系统 2023-05-19
- java基础知识之FileInputStream流的使用 2023-08-11
- Java实现线程插队的示例代码 2022-09-03
- springboot自定义starter方法及注解实例 2023-03-31
- JDK数组阻塞队列源码深入分析总结 2023-04-18
- Java数据结构之对象比较详解 2023-03-07
- ConditionalOnProperty配置swagger不生效问题及解决 2023-01-02
- Java实现查找文件和替换文件内容 2023-04-06
- Java文件管理操作的知识点整理 2023-05-19