Java 实现简易教务管理系统的代码

网友投稿 247 2022-11-29


Java 实现简易教务管理系统的代码

Main.java

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

System.out.println("\t\t简易教务管理系统");

System.out.println("1、录入学生\t2、显示学生\t3、录入课程\t4、显示课程\t5、录入教师"

+"\t6、显示教师\t7、学生选课\t8、教师录入成绩\t9、教师排课\t10、授课评价\t0、退出");

Student[] students=null;

Course courses[]=null;

Teacher teachers[]=null;

Operator operator=new Operator();

Scanner scan= new Scanner(System.in);

itcase: while (true) {

//显示系统主菜单

System.out.print("请选择功能菜单:");

int choice = scan.nextInt();// 接收用户的选择

switch(choice){

case 1: // 输入学生信息

System.out.println("请输入学生数:");

int n = scan.nextInt();

students = new Student[n];

operator.addStudents(students);

break;

case 2: // 显示全部学生信息

operator.displayStudents(students);

break;

case 3://录入课程

System.out.println("请输入课程数:");

n = scan.nextInt();

courses = new Course[n];

operator.addCourses(courses);

break;

case 4: // 显示课程

operator.displayCourses(courses);

break;

case 5: // 录入教师

System.out.println("请输入教师数:");

n = scan.nextInt();

teachers = new Teacher[n];

operator.addTeachers(teachers);

break;

case 6:// 显示教师

operator.displayTeachers(teachers);

break;

case 7:// 学生选课

operator.stuSelectCourses(students, courses);

break;

case 8:// 录入成绩

operator.inputScores(students);

break;

case 9:// 教师排课

operator.assignTeachCourses(teachers, courses);

break;

case 10:// 授课评价

operator.inputEvaluate(teachers);

break;

case 0:// 退出

break itcase;

default:

System.out.println("非法命令!");

}

}

}

Course.java

public class Course {

private String courseId;//课程号

private String courseName;//课程名称

private double credit;//学分

//构造方法

Course(){

}

Course(String courseId,String courseName,double credit){

this.setCourseId(courseId);

this.setCourseName(courseName);

this.setCredit(credit);

}

public String getCourseId() {

return courseId;

}

public void setCourseId(String courseId) {

this.courseId = courseId;

}

public String getCourseName() {

return courseName;

}

public void setCourseName(String courseName) {

this.courseName = courseName;

}

public double getCredit() {

return credit;

}

public void setCredit(double credit) {

this.credit = credit;

}

}

Operator.java

import java.util.Scanner;

public class Operator {

Scanner scan;

Operator(){

scan= new Scanner(System.in);

}

//录入课程

public void addCourses(Course[] courses){

System.out.println("请输入学生信息:格式为课程号,课程名,学分");

String str;

String sInfor[];

for(int i=0;i

str=scan.next();

sInfor=str.split(",");

courses[i]=new Course(sInfor[0],sInfor[1],Double.parseDouble(sInfor[2]));

}

}

//显示所有课程

public void displayCourses(Course[] courses){

for(int i=0;i

System.out.println("课程号:"+courses[i].getCourseId()+",课程名:"+courses[i].getCourseName()

+",学分:"+courses[i].getCredit());

}

}

//录入学生

public void addStudents(Student[] students){

System.out.println("请输入学生信息:格式为学号,姓名,性别,电话,地址,年龄");

String str;

String sInfor[];

for(int i=0;i

str=scan.next();

sInfor=str.split(",");

students[i]=new Student(sInfor[0],sInfor[1],sInfor[2],sInfor[3],

sInfor[4],Integer.parseInt(sInfor[5]));

}

}

//显示学生所有信息

public void displayStudents(Student[] students){

for(int i=0;i

System.out.println("学号:"+students[i].getStuId()+",姓名:"+students[i].getStuName()

+",性别:"+students[i].getSex()+",电话:"+students[i].getTel()

+",住址:"+students[i].getAddress()+",年龄:"+students[i].getAge());

if(students[i].selCourse!=null){

for(int j=0;j

System.out.println("\t\t课程编号:"+students[i].selCourse[j].courseId+",成绩:"

+students[i].selCourse[j].grade);

}

}

}

}

//录入教师

public void addTeachers(Teacher[] teachers){

System.out.println("请输入教师信息:格式为工号,姓名,性别,电话,职称,年龄");

String str;

String sInfor[];

for(int i=0;i

str=scan.next();

sInfor=str.split(",");

teachers[i]=new Teacher(sInfor[0],sInfor[1],sInfor[2],sInfor[3],sInfor[4],Integer.parseInt(sInfor[5]));

}

}

//显示教师所有信息

public void displayTeachers(Teacher[] teachers){

for(int i=0;i

System.out.println("工号:"+teachers[i].getTeaId()+",姓名:"+teachers[i].getTeaName()

+",性别:"+teachers[i].getSex()+",电话:"+teachers[i].getTel()

+",职称:"+teachers[i].getProfessor()+",年龄:"+teachers[i].getAge());

if(teachers[i].teachCourse!=null){

for(int j=0;j

System.out.println("\t\t课程编号:"+teachers[i].teachCourse[j].courseId+",授课评价:"+teachers[i].teachCourse[j].evaluate);

}

}

}

}

//学生选课

public void stuSelectCourses(Student[] students,Course[] courses){

System.out.println();

System.out.println("\t课程信息系如下:");

for(int i=0;i

System.out.println("课程号:"+courses[i].getCourseId()+"\t"+"课程名称:"

+courses[i].getCourseName());

}

System.out.println();

System.out.println("请选择选修课程,格式为:课程号1,课程号2,......");

for(int i=0;i

System.out.println("学号:"+students[i].getStuId()+",姓名:"

+students[i].getStuName()+" 选课:");

String str=scan.next();

String[] cIds=str.split(",");

students[i].setSelCourse(cIds);

}

}

//教师排课

public void assignTeachCourses(Teacher[] teachers,Course[] courses){

System.out.println();

System.out.println("\t课程信息系如下:");

for(int i=0;i

System.out.println("课程号:"+courses[i].getCourseId()

+"\t"+"课程名称:"+courses[i].getCourseName());

}

System.out.println();

System.out.println("请选择课程,格式为:课程号1,课程号2,......");

for(int i=0;i

System.out.println("工号:"+teachers[i].getTeaId()

+",姓名:"+teachers[i].getTeaName()+" 排课:");

String[] cIds=scan.next().split(",");

teachers[i].setTeachCourse(cIds);

}

}

//教师录入成绩

public void inputScores(Student[] students){

for(int i=0;i

for(int j=0;j

System.out.println("请输入学号:"+students[i].getStuId()

+",姓名:"+students[i].getStuName()

+", 课程编号为:"+students[i].selCourse[j].courseId+"的成绩:");

students[i].selCourse[j].grade=scan.nextDouble();

}

}

}

//教师授课评价

public void inputEvaluate(Teacher[] teachers){

for(int i=0;i

for(int j=0;j

System.out.println("请输入工号:"+teachers[i].getTeaId()+",姓名:"+teachers[i].getTeaName()

+", 课程编号为:"+teachers[i].teachCourse[j].courseId+"的授课评价:");

teachers[i].teachCourse[j].evaluate=scan.next();

}

}

}

//删除某门课程

public void delCourses(Course[] courses){

System.out.println("请输入要删除课程的编号:");

String courseId=scan.next();

for(int i=0;i

if(courses[i].getCourseId().equals(courseId)){

courses[i]=null;

}

}

}

}

Student.java

public class Student {

//设置Student类的属性

private String stuId; //学号

private String stuName; //姓名

private String sex; //性别

private String tel; //电话号码

private String address; //地址

private int age; //年龄

SelectCourse[] selCourse; //选修课程

//构造方法

Student(){

}

Student(String stuId,String stuName){

this.stuId=stuId;

this.stuName=stuName;

}

Student(String stuId,String stuName,String sex,String tel,String address,int age){

this(stuId,stuName); //this的用法

this.sex=sex;

this.tel=tel;

this.address=address; //地址

this.age=age;

}

public String getStuId() {

return stuId;

}

public void setStuId(String stuId) {

this.stuId = stuId;

}

//姓名属性封装

public String getStuName() {

return stuName;

}

public void setStuName(String stuName) {

this.stuName = stuName;

}

//性别属性封装

public String getSex() {

return sex;

}

public void setSex(String sex) {

this.sex = sex;

}

//电话属性封装

public String getTel() {

return tel;

}

public void setTel(String tel) {

this.tel = tel;

}

//地址属性封装

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

//年龄属性封装

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

//设置选修课程

public void setSelCourse(String[] cIds) { //cIds课程号数组 001,002

selCourse=new SelectCourse[cIds.length];

for(int j=0;j

selCourse[j]= new SelectCourse(cIds[j]);

}

}

//录入选修课程成绩

public void setSelCourseGrade(double[] grades) { //grades成绩数组

for(int j=0;j

selCourse[j].grade= grades[j];

}

}

//计算学生各门课程的平均成绩

double getAvg(){

double sum=0;

for(int i=0;i

sum=sum+selCourse[i].grade;

}

return sum/selCourse.length;

}

//计算学生各门课程的总和

double getSum(){

double sum=0;

for(int i=0;i

sum=sum+selCourse[i].grade;

}

return sum;

}

//内部类,用来记录选修的课程及成绩

class SelectCourse{

String courseId;

double grade;

SelectCourse(){

}

SelectCourse(String courseId)http://{

this.courseId=courseId;

}

SelectCourse(String courseId,double grade){

this.courseId=courseId;

this.grade=grade;

}

}

}

Teacher.java

public class Teacher {

//设置Teacher类的属性

private String teaId; //工号

private String teaName; //姓名

private String sex; //性别

private String tel; //电话

private String professor; //职称

private int age; //年龄

TeachCourse teachCourse[]; //所授课程

//构造方法

Teacher(){

}

Teacher(String teaId,String teaName){

this.teaId=teaId;

this.teaName=teaName;

}

Teacher(String teaId,String teaName,String sex,String tel,String professor,int age){

this(teaId,teaName); //this的用法

this.sex=sex;

this.tel=tel;

this.professor=professor; //地址

this.age=age;

}

//工号属性封装

public String getTeaId() {

return teaId;

}

public void setTeaId(String teaId) {

this.teaId = teaId;

}

//姓名属性封装

public String getTeaName() {

return teaName;

}

public void setTeaName(String teaName) {

this.teaName = teaName;

}

//性别属性封装

public String getSex() {

return sex;

}

public void setSex(String sex) {

this.sex = sex;

}

//电话属性封装

public String getTel() {

return tel;

}

public void setTel(String tel) {

this.tel = tel;

}

//职称属性封装

public String getProfessor() {

return professor;

}

public void setProfessor(String professor) {

this.professor = professor;

}

//年龄属性封装

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

//所授课程设置

public void setTeachCourse(String[] cIds) {

teachCourse=new TeachCourse[cIds.length];

for(int j=0;j

teachCourse[j]= new TeachCourse(cIds[j]);

}

}

//设置所授课程评价

public void setTeachEvaluate(String[] evaluates) { //grades成绩数组

for(int j=0;j

teachCourse[j].evaluate= evaluates[j];

}

}

//内部类,教师所授课程

class TeachCourse{

String courseId; //课程编号

String evaluate; //课程评价

TeachCourse(String courseId){

this.courseId=courseId;

}

TeachCourse(String courseId,String evaluate){

this.courseId=courseId;

this.evaluate=courseId;

}

}

}

ps/测试数据

01,张三,男,13500043567,浙江杭州,21

02,李四,男,13099872371,浙江温州,21

03,王五,男,13790972431,浙江金华,21

04,赵六,女,13190345445,浙江台州,21

05,孙七,女,13943298712,浙江湖州,21

001,Java编程,6

002,网页设计,3.5

003,AppInventor,2

01,李老师,男,13500043567,讲师,39

02,杨老师,女,13099872371,讲师,38

03,高老师,女,13790972431,副教授,39

04,赵老师,男,13190345445,副教授,56

05,孙老师,女,13943298712,教授,47


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java执行cmd命令两种实现方法解析
下一篇:Jmeter参数化实现原理及过程解析
相关文章

 发表评论

暂时没有评论,来抢沙发吧~