欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-04-05 17:44:21
main.javaimport java.util.scanner; public class main { public static void main(string[] args) {syste...

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<courses.length;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<courses.length;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<students.length;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<students.length;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<students[i].selcourse.length;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<teachers.length;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<teachers.length;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<teachers[i].teachcourse.length;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<courses.length;i++){
			system.out.println("课程号:"+courses[i].getcourseid()+"\t"+"课程名称:"
		        +courses[i].getcoursename());
		}
		system.out.println();
		system.out.println("请选择选修课程,格式为:课程号1,课程号2,......");
		for(int i=0;i<students.length;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<courses.length;i++){
			system.out.println("课程号:"+courses[i].getcourseid()
					    +"\t"+"课程名称:"+courses[i].getcoursename());
		}
		system.out.println();
		system.out.println("请选择课程,格式为:课程号1,课程号2,......");
		for(int i=0;i<teachers.length;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<students.length;i++){
			for(int j=0;j<students[i].selcourse.length;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<teachers.length;i++){
			for(int j=0;j<teachers[i].teachcourse.length;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<courses.length;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<cids.length;j++){
			selcourse[j]= new selectcourse(cids[j]);
		}
	}	
	//录入选修课程成绩
	public void setselcoursegrade(double[] grades) { //grades成绩数组
		for(int j=0;j<grades.length;j++){
			selcourse[j].grade= grades[j];
		}
	}	
	//计算学生各门课程的平均成绩
	double getavg(){
		double sum=0;
		for(int i=0;i<selcourse.length;i++){
			sum=sum+selcourse[i].grade;
		}
		return sum/selcourse.length;
	}
	
	//计算学生各门课程的总和
	double getsum(){
		double sum=0;
		for(int i=0;i<selcourse.length;i++){
			sum=sum+selcourse[i].grade;
		}
		return sum;
	}
	
	//内部类,用来记录选修的课程及成绩
	class selectcourse{
		string courseid;
		double grade;
		selectcourse(){
			
		}
		selectcourse(string courseid){
			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<cids.length;j++){
			teachcourse[j]= new teachcourse(cids[j]);
		}
	}
	//设置所授课程评价
	public void setteachevaluate(string[] evaluates) { //grades成绩数组
		for(int j=0;j<evaluates.length;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

到此这篇关于java 实现简易教务管理系统的代码的文章就介绍到这了,更多相关java教务管理系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!