Java实现简单的学生信息管理系统(二)-源码

Java实现简单的学生信息管理系统目录

github项目地址:https://github.com/asd123pwj/SimpleStudentManageSystemBasedOnJAVA
源码:https://mwhls.lanzous.com/iOCT3jw66le

学生信息管理系统源码-课程类

package school;

public class Course{
	public String courseName;
	public String courseNum;
	public double courseGrade;
	public boolean isFinish = false;
	
	//未考试的课程
	public Course(String courseName, String courseNum){					
		this.courseName = courseName;
		this.courseNum = courseNum;
	}
	
	//考完试的课程,构造方法重载
	public Course(String courseName, String courseNum, double grade){	
		this.courseName = courseName;
		this.courseNum = courseNum;
		this.courseGrade = grade;
		this.isFinish = true;
	}
	
	//为未考试的课程输入课程成绩
	public void inputGrade(double grade) {								
		courseGrade = grade;
		isFinish = true;
	}
}

学生信息管理系统源码-学生课程类

package school;


public class StudentCourse {
	Course courseGroup[];				//存储学生选课信息
	int failCourseNum = 0;				//学生挂科数
	int finishCourseNum = 0;			//学生结课数
	
	//显示学生选课课程信息
	public void showCourseInfo() {		
		if(courseGroup == null) return;
		for(Course course : courseGroup) {
			System.out.print("课程名称:"+course.courseName);
			System.out.print("\t课程号:"+course.courseNum);
			if(course.isFinish) {
				System.out.print("\t成绩:" + course.courseGrade);
			}
			System.out.println("");
		}
	}
	
	//增加学生课程
	public void addStudentCourse(String courseName, String courseNum) {
		addStudentCourse(new Course(courseName, courseNum));
	}

	//增加学生课程
	public void addStudentCourse(String courseName, String courseNum, double courseGrade) {
		addStudentCourse(new Course(courseName, courseNum, courseGrade));
	}
	
	//增加学生课程
	private void addStudentCourse(Course course) {	
		if(course.courseGrade<60 && course.isFinish) failCourseNum+=1;
		if(course.isFinish)	finishCourseNum += 1;		
		Course[] tempCourse = {course};
		if(courseGroup != null) {
			Course[] newCourse = new Course[courseGroup.length + 1];
			System.arraycopy(courseGroup, 0, newCourse, 0, courseGroup.length);
			System.arraycopy(tempCourse, 0, newCourse, newCourse.length-1, 1);
			courseGroup = newCourse;
		}
		else {
			courseGroup = tempCourse;
		}
	}
	
	//学生成绩录入
	public void inputStudentGrade(String courseNum, double grade) {
		boolean hasInput = false;
		for(Course course: courseGroup) {
			if(course.courseNum.contentEquals(courseNum)) {
				course.inputGrade(grade);
				finishCourseNum += 1;	
				course.isFinish = true;	
				if(course.courseGrade<60) failCourseNum+=1;
				hasInput = true;
			}
		}
		if(!hasInput)
			System.out.println("未找到该课程。");
	}
	
	//计算课程平均分
	public double getAverageGrade() {		
		double sum = 0;
		for(Course course:courseGroup) {
			sum += course.courseGrade;
		}
		return sum/(finishCourseNum);
	}
	
	//计算课程最低分
	public double getMinGrade() {			
		double min = 100;
		for(Course course:courseGroup) {
			if(course.isFinish)
				min = min<course.courseGrade ? min : course.courseGrade;
		}
		return min;
	}
	
	//计算课程最高分
	public double getMaxGrade() {			
		double max = 0;
		for(Course course:courseGroup) {
			if(course.isFinish)
				max = max>course.courseGrade ? max : course.courseGrade;
		}
		return max;
	}
	
}

学生信息管理系统源码-学生类

package school;

import java.util.*;



public class Student {
	public String studentNum;
	public String studentName;
	public String studentSex;
	public String studentAddr;
	public String studentSchool;
	public String studentAcademy;
	public String studentMajor;
	public StudentCourse studentCourse = new StudentCourse();
	
	public Student() {
		;
	}
	
	public Student(String num, String name, String sex, String addr, String school, String academy, String major){
		studentNum = num;
		studentName = name;
		studentSex = sex;
		studentAddr = addr;
		studentSchool = school;
		studentAcademy = academy;
		studentMajor = major;
	}
	
	//添加学生课程
	
	//显示学生信息。
	public void showStudentInfo() {	
		System.out.println("学号:" + studentNum);
		System.out.println("姓名:" + studentName);
		System.out.println("性别:" + studentSex);
		System.out.println("生源地:" + studentAddr);
		System.out.println("学校:" + studentSchool);
		System.out.println("学院:" + studentAcademy);
		System.out.println("专业:" + studentMajor);
//		showStudentCourseInfo();
	}
	
	public void showStudentCourseInfo() {
		studentCourse.showCourseInfo();
		if(studentCourse.courseGroup == null || studentCourse.finishCourseNum==0) return;
		getAverageGrade();
		System.out.println("最低分:"+getMinGrade()+",最高分:"+getMaxGrade());
		if(studentCourse.failCourseNum>=3) {
			System.out.println("!警告!当前学生挂科数过多,挂科数:" + studentCourse.failCourseNum);
		}
	}
	
	//计算课程平均分
	public void getAverageGrade() {			
		System.out.println("各课程平均分为:" + studentCourse.getAverageGrade());
	}
	
	//计算课程最低分
	public double getMinGrade() {			
		return studentCourse.getMinGrade();
	}
	
	//计算课程最高分
	public double getMaxGrade() {			
		return studentCourse.getMaxGrade();
	}
	
	public void addCourse(Scanner reader) {
		System.out.print("输入课程名称、课程号:");
		String courseName = reader.next();
		String courseNum = reader.next();
		System.out.print("课程已结课?y/n:");
		String hasGrade = reader.next();
		if(hasGrade.contentEquals("y")) {
			System.out.print("输入课程成绩:");
			double courseGrade = reader.nextDouble();
			studentCourse.addStudentCourse(courseName, courseNum, courseGrade);
		}
		else if(hasGrade.contentEquals("n")) {
			studentCourse.addStudentCourse(courseName, courseNum);
		}
	}
	
	public void addCourseGrade(Scanner reader) {
		System.out.print("请输入待修改成绩课程的课程号:");
		String courseNum = reader.next();
		System.out.print("请输入成绩:");
		double grade = reader.nextDouble();
		studentCourse.inputStudentGrade(courseNum, grade);
	}
	
}

学生信息管理系统源码-学生组类

package school;

import java.util.Scanner;

public class StudentGroup {
	Student[] studentGroup;
	
	public void addStudent(Scanner reader) {
		System.out.print("请输入学生学号、姓名、性别、生源地、所在学校、学院、专业:");
		String studentNum = reader.next();
		String studentName = reader.next();
		String studentSex = reader.next();
		String studentAddr = reader.next();
		String studentSchool = reader.next();
		String studentAcademy = reader.next();
		String studentMajor = reader.next();
		if(studentGroup == null) {
			studentGroup = new Student[1];
			studentGroup[0] = new Student(studentNum, studentName, studentSex, studentAddr, studentSchool, studentAcademy, studentMajor);
		}
		else {
			Student[] temp = new Student[1];
			temp[0] = new Student(studentNum, studentName, studentSex, studentAddr, studentSchool, studentAcademy, studentMajor);

			Student[] newGroup = new Student[studentGroup.length + 1];
			System.arraycopy(studentGroup, 0, newGroup, 0, studentGroup.length);
			System.arraycopy(temp, 0, newGroup, newGroup.length-1, 1);
			studentGroup = newGroup;
		}
	}
	
	public void showStudentGroup() {
		if(studentGroup == null) {
			System.out.println("无任何学生信息。");
			return;
		}
		System.out.println("学生学号列表:");
		for(Student student:studentGroup) {
			System.out.print(student.studentNum+" ");
		}
		System.out.println("");
	}
	
	public Student findStudent(Scanner reader) {
		System.out.print("输入学生学号:");
		String studentNum = reader.next();
		if(studentGroup == null) {
			System.out.println("无此学生。");
			return null;
		}
		for(Student student:studentGroup) {
			if(studentNum.contentEquals(student.studentNum)) {
				return student;
			}
		}
		System.out.println("无此学生。");
		return null;
	}
	
	public void addStudentCourse(Scanner reader) {
		Student student = findStudent(reader);
		if(student!=null)
			student.addCourse(reader);
	}
	
	public void inputStudentCourseGrade(Scanner reader) {
		Student student = findStudent(reader);
		if(student!=null)
			student.addCourseGrade(reader);
	}
	
	public void showStudentInfo(Scanner reader) {
		Student student = findStudent(reader);
		if(student!=null)
			student.showStudentInfo();
	}
	
	public void showStudentCourseInfo(Scanner reader) {
		Student student = findStudent(reader);
		if(student!=null)
			student.showStudentCourseInfo();
	}
	
}

学生信息管理系统源码-学校类

package school;

import java.util.*;

public class School {
	public static void main(String args[]) {
		boolean showMenu = true;
		Scanner reader = new Scanner(System.in);
		StudentGroup studentGroup = new StudentGroup();
		while(true) {
			if(showMenu) {
				System.out.println("\n学生管理菜单:");
				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("7.显示/隐藏学生管理菜单。");
				System.out.println("8.退出。");
				System.out.print("输入序号进入管理:");
			}
			else {
				System.out.print("输入序号进入管理(7:显示菜单):");
			}
			switch(reader.nextInt()) {
			case 1:
				studentGroup.showStudentGroup();
				break;
			case 2:
				studentGroup.addStudent(reader);
				break;
			case 3:
				studentGroup.addStudentCourse(reader);
				break;
			case 4:
				studentGroup.inputStudentCourseGrade(reader);
				break;
			case 5:
				studentGroup.showStudentInfo(reader);
				break;
			case 6:
				studentGroup.showStudentCourseInfo(reader);
				break;
			case 7:
				showMenu = !showMenu;
				break;
			case 8:
				reader.close();
				return ;
			}
		}
	}
}

研究生信息管理系统源码-研究生类

package graduateSchool;

import school.Student;


public class GraduateStudent extends Student {
	public String tutorName;
	public String researchName;
	
	//在子类中使用父类构造方法
	GraduateStudent(String num, String name, String sex, String addr, String school, String academy, String major, String tutorName, String researchName){
		super(num, name, sex, addr, school, academy, major);
		this.tutorName = tutorName;
		this.researchName = researchName;
	}
	
	//计算课程平均分,覆盖父类方法。
	public void getAverageGrade() {		
		System.out.println(this.studentName + "为研究生,其平均成绩为:" + studentCourse.getAverageGrade());
	}
	
	//研究生信息展示,覆盖父类方法,并调用被覆盖的父类方法。
	public void showStudentInfo() {		
		System.out.println("\n"+super.studentName+"为研究生。");
		super.showStudentInfo();
		System.out.println("导师:"+ tutorName);
		System.out.println("课题名称:"+ researchName);
	}
	
}

研究生信息管理系统源码-研究生组类

package graduateSchool;

import java.util.Scanner;
import school.*;

public class GraduateStudentGroup extends StudentGroup {
	Student[] studentGroup;
	
	public void addStudent(Scanner reader) {
		System.out.print("请输入研究生学号、姓名、性别、生源地、所在学校、学院、专业、导师名、课题名称:");
		String studentNum = reader.next();
		String studentName = reader.next();
		String studentSex = reader.next();
		String studentAddr = reader.next();
		String studentSchool = reader.next();
		String studentAcademy = reader.next();
		String studentMajor = reader.next();
		String tutorName = reader.next();
		String researchName = reader.next();
		if(studentGroup == null) {
			studentGroup = new GraduateStudent[1];
			studentGroup[0] = new GraduateStudent(studentNum, studentName, studentSex, studentAddr, studentSchool, studentAcademy, studentMajor, tutorName, researchName);
		}
		else {
			Student[] temp = new GraduateStudent[1];
			temp[0] = new GraduateStudent(studentNum, studentName, studentSex, studentAddr, studentSchool, studentAcademy, studentMajor, tutorName, researchName);

			Student[] newGroup = new GraduateStudent[studentGroup.length + 1];
			System.arraycopy(studentGroup, 0, newGroup, 0, studentGroup.length);
			System.arraycopy(temp, 0, newGroup, newGroup.length-1, 1);
			studentGroup = newGroup;
		}
	}
	
	public void showStudentGroup() {
		if(studentGroup == null) {
			System.out.println("无任何学生信息。");
			return;
		}
		System.out.println("学生学号列表:");
		for(Student student:studentGroup) {
			System.out.print(student.studentNum+" ");
		}
		System.out.println("");
	}
	
	public Student findStudent(Scanner reader) {
		System.out.print("输入学生学号:");
		String studentNum = reader.next();
		if(studentGroup == null) {
			System.out.println("无此学生。");
			return null;
		}
		for(Student student:studentGroup) {
			if(studentNum.contentEquals(student.studentNum)) {
				return student;
			}
		}
		System.out.println("无此学生。");
		return null;
	}
	
}

研究生信息管理系统源码-学校类

package graduateSchool;

import java.util.*;

public class School {
	public static void main(String args[]) {
		boolean showMenu = true;
		Scanner reader = new Scanner(System.in);
		GraduateStudentGroup studentGroup = new GraduateStudentGroup();
		while(true) {
			if(showMenu) {
				System.out.println("\n研究生管理菜单:");
				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("7.显示/隐藏研究生管理菜单。");
				System.out.println("8.退出。");
				System.out.print("输入序号进入管理:");
			}
			else {
				System.out.print("输入序号进入管理(7:显示菜单):");
			}
			switch(reader.nextInt()) {
			case 1:
				studentGroup.showStudentGroup();
				break;
			case 2:
				studentGroup.addStudent(reader);
				break;
			case 3:
				studentGroup.addStudentCourse(reader);
				break;
			case 4:
				studentGroup.inputStudentCourseGrade(reader);
				break;
			case 5:
				studentGroup.showStudentInfo(reader);
				break;
			case 6:
				studentGroup.showStudentCourseInfo(reader);
				break;
			case 7:
				showMenu = !showMenu;
				break;
			case 8:
				reader.close();
				return ;
			}
		}
	}
}

You may also like...

发表评论

邮箱地址不会被公开。 必填项已用*标注