View包
UserView.java
package views; import controller.UserController; import entity.User; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.List; /** * @Author: hyy * @Date: 2020/12/18 15:33 */ public class UserView { BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in)); protected UserController userController=new UserController(); /** * * @return */ public boolean ordinaryStudentLoginView(){ try { System.out.println("欢迎进入学生登录界面"); System.out.println("请输入id"); String id=bufferedReader.readLine(); System.out.println("请输入密码:"); String password=bufferedReader.readLine(); return userController.ordinaryUserLogin(Integer.parseInt(id),password); }catch (IOException e){ System.out.println("io异常,登录失败!"); return false; } } /** * * @return */ public boolean ordinaryTeacherLoginView(){ try { System.out.println("欢迎进入教师登录界面"); System.out.println("请输入id"); String id=bufferedReader.readLine(); System.out.println("请输入密码:"); String password=bufferedReader.readLine(); return userController.ordinaryUserLogin(Integer.parseInt(id),password); }catch (IOException e){ System.out.println("io异常,登录失败!"); return false; } } /** * * @return */ public boolean administratorLoginView(){ try { System.out.println("欢迎进入管理员登录界面"); System.out.println("请输入id"); String id=bufferedReader.readLine(); System.out.println("请输入密码:"); String password=bufferedReader.readLine(); return userController.administratorLogin(Integer.parseInt(id),password); }catch (IOException e){ System.out.println("io异常,登录失败!"); return false; } } /** * 学生注册页面 * (权限绑定为1) * @return boolean */ public boolean registerStudentView(){ try { System.out.println("欢迎进入注册界面"); System.out.println("请输入您想要的id:"); String id=bufferedReader.readLine(); User user=userController.selectUserById(Integer.parseInt(id)); if (user==null){ System.out.println("请输入您的用户名:"); String userName=bufferedReader.readLine(); System.out.println("请输入您的密码"); String passWord=bufferedReader.readLine(); System.out.println("请输入您的密保问题:"); String question=bufferedReader.readLine(); System.out.println("请输入您的密保答案:"); String answer=bufferedReader.readLine(); User user1=new User(Integer.parseInt(id),userName,passWord,question,answer,1); System.out.println(user1); return userController.registerUser(user1); } }catch (IOException e){ System.out.println("io异常,登录失败!"); return false; } return false; } /** * 教师注册页面 * 权限绑定为2 * @return boolean */ public boolean registerTeacherView(){ try { System.out.println("欢迎进入注册界面"); System.out.println("请输入您想要的id:"); String id=bufferedReader.readLine(); User user=userController.selectUserById(Integer.parseInt(id)); if (user==null){ System.out.println("请输入您的用户名:"); String userName=bufferedReader.readLine(); System.out.println("请输入您的密码"); String passWord=bufferedReader.readLine(); System.out.println("请输入您的密保问题:"); String question=bufferedReader.readLine(); System.out.println("请输入您的密保答案:"); String answer=bufferedReader.readLine(); User user1=new User(Integer.parseInt(id),userName,passWord,question,answer,2); System.out.println(user1); return userController.registerUser(user1); } else{ System.out.println("该id已存在,注册失败!"); return false; } }catch (IOException e){ System.out.println("io异常,登录失败!"); return false; } } /** * 添加用户页面 * @return boolean */ public boolean insertUserView(){ try { System.out.println("欢迎进入增加用户界面"); System.out.println("请输入想要添加的用户id"); String id=bufferedReader.readLine(); User user=userController.selectUserById(Integer.parseInt(id)); if (user==null){ System.out.println("请输入想要添加的用户名:"); String userName=bufferedReader.readLine(); System.out.println("请输入密码:"); String passWord=bufferedReader.readLine(); System.out.println("请输入用户权限:"); String level=bufferedReader.readLine(); User user1=new User(Integer.parseInt(id),userName,passWord,null,null,Integer.parseInt(level)); System.out.println(user1); return userController.insertUser(user1); } }catch (IOException e){ System.out.println("io异常,添加失败!"); return false; } return false; } /** * 删除用户页面 * @return boolean */ public boolean deleteUserView(){ try { System.out.println("欢迎进入删除用户界面"); System.out.println("请输入想要删除的用户id"); String id= null; id = bufferedReader.readLine(); return userController.deleteUserById(Integer.parseInt(id)); } catch (IOException e) { System.out.println("io异常,添加失败!"); return false; } } /** * 更改用户页面 * @return boolean */ public boolean updateUserView(){ try { System.out.println("欢迎进入更改用户信息界面"); System.out.println("请输入用户id:"); String id=bufferedReader.readLine(); System.out.println("请输入密保答案:"); String answer=bufferedReader.readLine(); User user=userController.selectUserById(Integer.parseInt(id)); if (answer.equals(user.getAnswer())){ System.out.println("请输入想要修改成的用户名"); String userName=bufferedReader.readLine(); System.out.println("请输入想要改成的密码:"); String password=bufferedReader.readLine(); User user1=new User(user.getId(),userName,password,user.getQuestion(),user.getAnswer(),user.getLevel()); return userController.updateUserById(Integer.parseInt(id),user1); } }catch (IOException e){ System.out.println("io异常,更改失败!"); return false; } return false; } /** * 查询用户页面 * @return void */ public void selectUserViewO(){ try { System.out.println("********欢迎来到查询页面!********"); System.out.println("请选择你要选择的查询方式:"); System.out.println(" 1.查所有,2.根据id查询,3.根据用户名查询 "); switch (Integer.parseInt(bufferedReader.readLine())){ case 1: List<User> userList=userController.selectAllUser(); System.out.println("查询的结果是:"); System.out.println(userList.toString()); break; case 2: System.out.println("请输入你想要查询的id"); String id=bufferedReader.readLine(); User user=userController.selectUserById(Integer.parseInt(id)); System.out.println("查询的结果是:"); System.out.println(user.toString()); break; case 3: System.out.println("请输入你想查询的用户名"); String userName=bufferedReader.readLine(); User user1=userController.selectUserByUserName(userName); System.out.println("查询的结果是:"); System.out.println(user1.toString()); break; default: System.out.println("输入指令错误!"); } }catch (IOException e){ System.out.println("查询失败!"); } } }
CourseView.java
package views; import controller.CourseController; import controller.UserController; import entity.Course; import entity.User; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * @Author: hyy * @Date: 2020/12/18 22:37 */ public class CourseView { CourseController courseController=new CourseController(); /** * 创建一个用户方向的对象 用来去 调用根据id查询用户方法 和getAnswer * 去吧user和课程连接到一起、 */ UserController userController=new UserController(); /** * 一般流开了需要调close关掉,但是这种不可以关 !!! * new BufferedReader(new InputStreamReader(System.in)); * 还有try(){}catch{} 这种try括号里是会自动关闭资源的 * 所以一般流写里面不用再刻意去关闭 * 也因此上面的这种代码不可以放到那个括号里 */ BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in)); /** * 添加课程页面 * @return boolean */ public boolean insertCourseView(){ try { System.out.println("—————————欢迎进入添加课程界面————————"); System.out.println("请输入想要添加的课程的用户id"); String id=bufferedReader.readLine(); System.out.println("请输入密保答案:"); String answer=bufferedReader.readLine(); User user= userController.selectUserById(Integer.parseInt(id)); if (user.getAnswer().equals(answer)){ System.out.println("请输入想要添加的课程名称:"); String courseName=bufferedReader.readLine(); System.out.println("请输入课程编号:"); String courseId=bufferedReader.readLine(); System.out.println("请输入课程任课老师:"); String courseTeacher=bufferedReader.readLine(); System.out.println("请输入课程可选人数:"); String courseNumber=bufferedReader.readLine(); Course course1=new Course(Integer.parseInt(id),courseName,courseId,courseTeacher,Integer.parseInt(courseNumber)); System.out.println(course1); return courseController.insertCourseController(course1); } }catch (IOException e){ System.out.println("io异常,添加失败!"); return false; } return false; } /** * 删除课程页面 * @return boolean */ public boolean deleteCourseView(){ try { System.out.println("—————————欢迎进入删除课程界面————————"); System.out.println("请输入想要删除的课程的用户id"); String id=bufferedReader.readLine(); System.out.println("请输入想要删除的课程的课程编号:"); String courseId=bufferedReader.readLine(); System.out.println("请输入密保答案:"); String answer=bufferedReader.readLine(); User user= userController.selectUserById(Integer.parseInt(id)); if (user.getAnswer().equals(answer)){ return courseController.deleteCourseByCourseIdController(Integer.parseInt(id),courseId); } }catch (IOException e){ System.out.println("io异常,删除失败!"); return false; } return false; } /** * 更改课程页面 * @return boolean */ public boolean updateCourseView(){ try { System.out.println("—————————欢迎进入更改课程界面————————"); System.out.println("请输入想要更改的课程的用户id"); String id=bufferedReader.readLine(); System.out.println("请输入想要更改的课程的课程编号"); String courseId=bufferedReader.readLine(); System.out.println("请输入密保答案:"); String answer=bufferedReader.readLine(); System.out.println("请输入想要添加的课程名称:"); String courseName=bufferedReader.readLine(); System.out.println("请输入课程编号:"); String courseId1=bufferedReader.readLine(); System.out.println("请输入课程任课老师:"); String courseTeacher=bufferedReader.readLine(); System.out.println("请输入课程可选人数:"); String courseNumber=bufferedReader.readLine(); Course course=new Course(Integer.parseInt(id),courseName,courseId1,courseTeacher,Integer.parseInt(courseNumber)); User user= userController.selectUserById(Integer.parseInt(id)); if (user.getAnswer().equals(answer)){ return courseController.updateCourseByIdService(Integer.parseInt(id),courseId,course); } }catch (IOException e){ System.out.println("io异常,删除失败!"); return false; } return false; } /** * 查询课程页面 */ public void selectCourseView(){ try { System.out.println("————————欢迎来到课程查询页面!————————"); System.out.println("请选择你要选择的查询方式:"); System.out.println(" 1.查所有人的课程,2.根据id查询该用户课程"); switch (Integer.parseInt(bufferedReader.readLine())){ case 1: System.out.println("请输入您的id:"); String id1=bufferedReader.readLine(); User user=userController.selectUserById(Integer.parseInt(id1)); if (user.getLevel()==3||user.getLevel()==2) { System.out.println(courseController.selectAllCourseService()); }else { System.out.println("抱歉,您没有权限访问!"); } break; case 2: System.out.println("请输入你想要查询的id:"); String id=bufferedReader.readLine(); System.out.println("请输入密保答案:"); String answer=bufferedReader.readLine(); User user1=userController.selectUserById(Integer.parseInt(id)); if (user1.getAnswer().equals(answer)){ System.out.println(courseController.selectCourseByIdController(Integer.parseInt(id))); }else { System.out.println("答案错误,查询失败!"); } break; default: System.out.println("输入指令错误!"); break; } }catch (IOException e){ System.out.println("io异常,查询失败!"); } } }
Sepration.java
package views; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * @Author: hyy * @Date: 2020/12/18 20:17 * 最终页面 */ public class SeparationView { UserView userView=new UserView(); CourseView courseView=new CourseView(); BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in)); int tool=0; boolean judgement=false; String a=null; public void separation(){ try { System.out.println("————————是否进入学生选课系统?——————————"); System.out.println("——————————如果进入系统请输入yes,如果要不进入系统输入其他即可————————"); a=bufferedReader.readLine(); while (a.equals("yes")){ System.out.println("欢迎来到学生选课系统!!!"); System.out.println("——————————请输入你要进入的界面——————————"); System.out.println("1.学生登录,2.教师登录,3.管理员登录,4.学生注册,5,教师注册"); try { switch (Integer.parseInt(bufferedReader.readLine())){ case 1: judgement=userView.ordinaryStudentLoginView(); tool=1; break; case 2: judgement=userView.ordinaryTeacherLoginView(); tool=2; break; case 3: judgement=userView.administratorLoginView(); tool=3; break; case 4: userView.registerStudentView(); judgement=userView.ordinaryStudentLoginView(); tool=1; break; case 5: userView.registerTeacherView(); judgement=userView.ordinaryTeacherLoginView(); tool=2; break; default: System.out.println("输入指令异常!"); break; } if (judgement&&tool==3){ System.out.println("-------请输入你要进入的界面----------"); System.out.println("1.增加用户 2.删除用户 3.更改用户 4.查询用户 5.添加课程 6.删除课程 7.更改课程 8.查询课程"); switch (Integer.parseInt(bufferedReader.readLine())){ case 1: userView.insertUserView(); break; case 2: userView.deleteUserView(); break; case 3: userView.updateUserView(); break; case 4: userView.selectUserViewO(); break; case 5: courseView.insertCourseView(); break; case 6: courseView.deleteCourseView(); break; case 7: courseView.updateCourseView(); break; case 8: courseView.selectCourseView(); break; default: System.out.println("输入指令错误!"); break; } }else if (judgement&&tool==2){ System.out.println("-------请输入你要进入的界面----------"); System.out.println("1.更改个人信息 2.查询课程 "); switch (Integer.parseInt(bufferedReader.readLine())){ case 1: userView.updateUserView(); break; case 2: courseView.selectCourseView(); break; default: System.out.println("输入指令错误!"); break; } }else if (judgement&&tool==1){ System.out.println("-------请输入你要进入的界面----------"); System.out.println(" 1.更改个人信息 2.选课 3.退课 4.改课 5.查课"); switch (Integer.parseInt(bufferedReader.readLine())){ case 1: userView.updateUserView(); break; case 2: courseView.insertCourseView(); break; case 3: courseView.deleteCourseView(); break; case 4: courseView.updateCourseView(); break; case 5: courseView.selectCourseView(); break; default: System.out.println("输入指令错误!"); break; } } }catch (IOException e){ System.out.println("io异常,进入失败!"); } System.out.println("是否重新进入系统?"); System.out.println("如果重新进入请输入yes,如果要退出系统输入其他即可"); a=bufferedReader.readLine(); } System.out.println("欢迎下次进入!"); }catch (IOException e){ System.out.println("io异常,进入失败!"); } } }
Test 测试类
import views.SeparationView; /** * @Author: hyy * @Date: 2020/12/18 13:07 */ public class UniversitySelectionCourseSystemTest { public static void main(String[] args) { SeparationView separationView=new SeparationView(); separationView.separation(); } }
uril包
Create.java
建文件夹及文件
package util; /** * @Author: hyy * @Date: 2020/12/18 13:08 */ public class Create { public static void main(String[] args) { CreateFileName createFileName=new CreateFileName(); CreatePathName createPathName=new CreatePathName(); // 创建目录 createPathName.create("UniversityCourseSelectionSystem"); // 创建文件 createFileName.create("UniversityCourseSelectionSystem\\User.txt"); createFileName.create("UniversityCourseSelectionSystem\\Order.txt"); createFileName.create("UniversityCourseSelectionSystem\\Course.txt"); } }
CreateFileName
创建文件
package util; import java.io.File; import java.io.IOException; /** * @Author: hyy * @Date: 2020/12/18 13:09 */ public class CreateFileName { /** * 创建文件 * @param Filename * @return boolean */ public boolean create(String Filename){ try { File file=new File(Filename); file.createNewFile(); if (file.exists()){ return false; } if (file.createNewFile()){ return true; } else { return false; } }catch (IOException e){ return false; } } }
CreatePathName.java
创建目录
package util; import java.io.File; /** * @Author: hyy * @Date: 2020/12/18 13:08 */ public class CreatePathName { /** * 创建目录 * @param Filename * @return */ public boolean create(String Filename){ File file=new File(Filename); if (file.exists()){ return false; } if (!Filename.endsWith(File.separator)) { Filename = Filename + File.separator; } if (file.mkdir()) { return true; } else { return false; } } }