import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;
public class TeachingManagementSystem {
private static final String DB_URL = "jdbc:mysql://localhost:3306/teaching_management_system";
private static final String DB_USER = "root";
private static final String DB_PASSWORD = "root";
private Scanner scanner;
private Connection connection;
public TeachingManagementSystem() {
scanner = new Scanner(System.in);
}
public void start() {
if (!connectToDatabase()) {
System.out.println("连接数据库失败!");
return;
}
while (true) {
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("7. 添加课程");
System.out.println("8. 查询课程");
System.out.println("9. 学生选课");
System.out.println("10. 登记考试成绩");
System.out.println("11. 补考处理");
System.out.println("12. 学生成绩统计");
System.out.println("13. 教师教学工作量统计");
System.out.println("14. 为教师添加课程");
System.out.println("15. 输入教师工号查询授课列表");
System.out.println("0. 退出系统");
System.out.println("************************************");
System.out.print("请选择操作:");
int choice = Integer.parseInt(scanner.nextLine());
switch (choice) {
case 1:
addDepartment(); // 调用添加院系的方法
break;
case 2:
queryDepartments(); // 调用查询院系的方法
break;
case 3:
addTeacher();
break;
case 4:
queryTeachers();
break;
case 5:
addStudent();
break;
case 6:
queryStudents();
break;
case 7:
addCourse();
break;
case 8:
queryCourses();
break;
case 9:
// studentSelectCourse();
enrollCourse();//选课
break;
case 10:
recordExamScore();//登记成绩
break;
case 11:
makeUpExam();//补考
break;
case 12:
calculateStudentScores();//学生成绩统计
break;
case 13:
calculateTeacherWorkloads();//教学工作量统计
break;
case 14:
addCourseToTeacher();
break;
case 15:
printTeacherCourseList();
break;
case 0:
exit();
return;
default:
System.out.println("无效的操作,请重新选择!");
}
System.out.println();
}
}
public void addDepartment() {
System.out.print("请输入新院系的名称:");
String departmentName = scanner.nextLine();
System.out.print("请输入院系的负责人:");
String head = scanner.nextLine();
try {
String checkSql = "SELECT COUNT(*) FROM department WHERE name = ?";
PreparedStatement checkStatement = connection.prepareStatement(checkSql);
checkStatement.setString(1, departmentName);
ResultSet resultSet = checkStatement.executeQuery();
if (resultSet.next()) {
int count = resultSet.getInt(1);
if (count > 0) {
System.out.println("该院系已经存在了");
return; // 如果该院系已经存在,则直接返回,不执行插入操作
}
}
String sql = "INSERT INTO department (name,head) VALUES (?,?)";
PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, departmentName);
statement.setString(2, head);
int rowsAffected = statement.executeUpdate();
if (rowsAffected > 0) {
System.out.println("添加院系成功!");
} else {
System.out.println("添加院系失败!");
}
statement.close();
} catch (SQLException e) {
e.printStackTrace();
System.out.println("添加院系失败!出现异常:" + e.getMessage());
}
}
public void queryDepartments() {
try {
String sql = "SELECT * FROM department";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
int departmentId = resultSet.getInt("id");
String departmentName = resultSet.getString("name");
String head = resultSet.getString("head");
System.out.printf("院系ID: %d, 院系名称: %s,负责人: %s\n", departmentId, departmentName, head);
System.out.println("------------------------");
}
resultSet.close();
statement.close();
} catch (SQLException e) {
e.printStackTrace();
System.out.println("查询院系失败!出现异常:" + e.getMessage());
}
}
private boolean connectToDatabase() {
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
System.out.println("连接数据库成功!");
createTablesIfNotExist();
return true;
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
private void createTablesIfNotExist() throws SQLException {
Statement statement = connection.createStatement();
String createCourseTableSql = "CREATE TABLE IF NOT EXISTS courses (" +
"id INT PRIMARY KEY AUTO_INCREMENT," +
"name VARCHAR(100) NOT NULL," +
"credit INT NOT NULL," +
"class_hours INT NOT NULL," +
"type VARCHAR(10) NOT NULL" +
")";
statement.executeUpdate(createCourseTableSql);
String createStudentTableSql = "CREATE TABLE IF NOT EXISTS students (" +
"id INT PRIMARY KEY AUTO_INCREMENT," +
"student_id VARCHAR(20) NOT NULL," +
"name VARCHAR(100) NOT NULL," +
"gender VARCHAR(10) NOT NULL," +
"age INT NOT NULL," +
"department VARCHAR(100) NOT NULL" +
")";
statement.executeUpdate(createStudentTableSql);
String createTeacherTableSql = "CREATE TABLE IF NOT EXISTS teachers (" +
"id INT PRIMARY KEY AUTO_INCREMENT," +
"teacher_id INT NOT NULL," +
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
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("7. 添加课程"); System.out.println("8. 查询课程"); System.out.println("9. 学生选课"); System.out.println("10. 登记考试成绩");
资源推荐
资源详情
资源评论
收起资源包目录
javaProject控制台教学管理系统zip.zip (17个子文件)
javaProject
jxxtold.rar 2.24MB
jxxt20231101.rar 2.25MB
jxxt.rar 2.23MB
jxxt
lib
mysql-connector-j-8.0.32.jar 2.37MB
teaching_management_system1101.sql 5KB
jxxt.iml 516B
src
TeachingManagementSystem1.java 15KB
TeachingManagementSystem.java 43KB
TeachingManagementSystem2.java 111B
teaching_management_system.sql 4KB
out
production
jxxt
TeachingManagementSystem1.class 11KB
TeachingManagementSystem.class 24KB
TeachingManagementSystem2.class 300B
.idea
libraries
mysql_connector_j_8_0_32.xml 246B
workspace.xml 5KB
misc.xml 278B
modules.xml 255B
共 17 条
- 1
资源评论
Summer524!
- 粉丝: 47
- 资源: 115
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 量化交易-RSI策略(vectorbt实现)
- Java答题期末考试必须考
- 组播报文转发原理的及图解实例
- 青龙燕铁衣-数据集.zip
- 指针扫描和内存遍历二合一工具
- 基于JavaScript的在线考试系统(编号:65965158)(1).zip
- 五相电机双闭环矢量控制模型-采用邻近四矢量SVPWM-MATLAB-Simulink仿真模型包括: (1)原理说明文档(重要):包括扇区判断、矢量作用时间计算、矢量作用顺序及切时间计算、PWM波的生成
- Linux下的cursor安装包
- springboot-教务管理系统(编号:62528147).zip
- 3dmmods_倾城系列月白_by_白嫖萌新.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功