View
//用户View层 import studio.lyl.questionbankmanagementsystem.controller.UserController; import studio.lyl.questionbankmanagementsystem.entity.User; import studio.lyl.questionbankmanagementsystem.service.IUserService; import studio.lyl.questionbankmanagementsystem.service.impl.UserServiceImpl; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * @Author: Re * @Date: 2020/12/11 22:28 */ public class UserView { BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in)); UserController userController=new UserController(); String id= null; public boolean loginAdministrator(){ System.out.println("欢迎进入登录界面"); System.out.println("请输入账号"); String password=null; try { boolean re=true; while (re){ id = bufferedReader.readLine(); if(id==null){ System.out.println("输入的账号有误请,重新输入"); continue; }else { try { Integer.parseInt(id); } catch (NumberFormatException e) { System.out.println("输入的账号有误请,重新输入"); continue; } } re=false; } System.out.println("请输入密码"); password=bufferedReader.readLine(); } catch (IOException e) { e.printStackTrace(); } return userController.loginAdministrator(Integer.parseInt(id),password); } public boolean loginUser() { System.out.println("欢迎进入登录界面"); System.out.println("请输入账号"); String password=null; try { boolean re=true; while (re){ id = bufferedReader.readLine(); if(id==null){ System.out.println("输入的账号有误请,重新输入"); continue; }else { try { Integer.parseInt(id); } catch (NumberFormatException e) { System.out.println("输入的账号有误请,重新输入"); continue; } } re=false; } System.out.println("请输入密码"); password=bufferedReader.readLine(); } catch (IOException e) { e.printStackTrace(); } return userController.loginUser(Integer.parseInt(id),password); } public void registUser() { System.out.println("欢迎进入注册界面"); System.out.println("请输入您想要的账号"); try { boolean re=true; while (re){ id = bufferedReader.readLine(); if(id==null){ System.out.println("输入的账号有误请,重新输入"); continue; }else { try { Integer.parseInt(id); } catch (NumberFormatException e) { System.out.println("输入的账号有误请,重新输入"); continue; } } re=false; } System.out.println("请输入你的密码"); String password=bufferedReader.readLine(); System.out.println("请输入你的昵称"); String userName=bufferedReader.readLine(); User user=new User(Integer.parseInt(id),password,userName,0,0,0); userController.registUser(user); } catch (IOException e) { e.printStackTrace(); } } public void insertUser() { System.out.println("欢迎进入增加用户界面"); System.out.println("请输入您想要的账号"); String id= null; try { id = bufferedReader.readLine(); System.out.println("请输入您的密码"); String password=bufferedReader.readLine(); System.out.println("请输入你的昵称"); String userName=bufferedReader.readLine(); User user=new User(Integer.parseInt(id),password,userName,0,0,0); userController.insertUser(user); } catch (IOException e) { e.printStackTrace(); } } public void deleteUserById() { System.out.println("欢迎进入用户删除界面"); System.out.println("请输入您想删除的用户账号"); String userId; try { userId = bufferedReader.readLine(); userController.deleteUserById(Integer.parseInt(userId)); bufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } } public void updateUser() { System.out.println("欢迎进入更改用户信息界面"); try { IUserService iUserService=new UserServiceImpl(); User userInterposition=iUserService.selectUserById(Integer.parseInt(id)); System.out.println("请输入新密码"); String updatePassword=bufferedReader.readLine(); System.out.println("请输入新昵称"); String updateUserName=bufferedReader.readLine(); User user=new User(Integer.parseInt(id),updatePassword,updateUserName,userInterposition.getNodeCount(),userInterposition.getCollectionCount(),userInterposition.getLevel()); userController.updateUser(Integer.parseInt(id),user); } catch (IOException e) { e.printStackTrace(); } } public void selectUserById() { System.out.println("欢迎进入用户查询界面"); System.out.println("用户信息如下"); userController.selectUserById(Integer.parseInt(id)); } public void selectUser() { System.out.println("欢迎进入用户查询界面"); System.out.println("用户信息如下"); userController.selectUser(); } } //题库View层 import studio.lyl.questionbankmanagementsystem.controller.QuestionsController; import studio.lyl.questionbankmanagementsystem.entity.Questions; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.List; /** * @Author: Re * @Date: 2020/12/11 22:29 */ public class QuestionsView { QuestionsController questionsController=new QuestionsController(); BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in)); public void insetQuestion() { System.out.println("欢迎进入添加题目界面"); System.out.println("请输入题目类型"); System.out.println("类型可分为 Math,English,Thought,HighLevelLanguage。"); String type= null; try { type = bufferedReader.readLine(); System.out.println("请输入内容"); String content=bufferedReader.readLine(); System.out.println("请输入题目答案"); String answer=bufferedReader.readLine(); System.out.println("请输入题目难易程度"); String complexity=bufferedReader.readLine(); List<Questions> questionsList=questionsController.selectQuestions(type); if (questionsList==null){ Questions questions = new Questions(content, type, 1, complexity, answer); questionsController.insetQuestion(questions); }else { Questions questions = new Questions(content, type, questionsList.size() + 1, complexity, answer); questionsController.insetQuestion(questions); } System.out.println("添加题目成功"); } catch (IOException e) { e.printStackTrace(); } } public void deleteQuestion() { System.out.println("欢迎进入删除题目页面"); System.out.println("请输入题目类型"); System.out.println("类型可分为 Math,English,Thought,HighLevelLanguage。"); String type= null; try { type = bufferedReader.readLine(); System.out.println("请输入题目序号"); String sign=bufferedReader.readLine(); questionsController.deleteQuestion(Integer.parseInt(sign),type); } catch (IOException e) { e.printStackTrace(); } } public void updateQuestion() { System.out.println("欢迎进入更改题目界面"); System.out.println("请输入更改题目类型"); System.out.println("类型可分为 Math,English,Thought,HighLevelLanguage。"); String type= null; try { type = bufferedReader.readLine(); System.out.println("请输入更改题目的序号"); String sign=bufferedReader.readLine(); System.out.println("请输入更改后内容"); String content=bufferedReader.readLine(); System.out.println("请输入更改后题目答案"); String answer=bufferedReader.readLine(); System.out.println("请输入更改后题目难易程度"); String complexity=bufferedReader.readLine(); Questions questions=new Questions(content,type,Integer.parseInt(sign),complexity,answer); questionsController.updateQuestion(Integer.parseInt(sign),type,questions); } catch (IOException e) { e.printStackTrace(); } } public void selectAnswer(int sign,String type){ questionsController.selectAnswer(sign,type); } public void selectQuestion(int sign,String type) { System.out.println(questionsController.selectQuestion(sign,type)); } public void selectQuestions(String type) { questionsController.selectQuestions(type); } } //笔记View层 import studio.lyl.questionbankmanagementsystem.controller.NoteController; import studio.lyl.questionbankmanagementsystem.entity.Note; import studio.lyl.questionbankmanagementsystem.entity.User; import studio.lyl.questionbankmanagementsystem.service.IUserService; import studio.lyl.questionbankmanagementsystem.service.impl.UserServiceImpl; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.List; /** * @Author: Re * @Date: 2020/12/11 22:29 */ public class NoteView { NoteController noteController = new NoteController(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); String id; public void insetNote() { System.out.println("欢迎进入添加笔记界面"); System.out.println("请输入用户的id"); try { IUserService iUserService = new UserServiceImpl(); id = bufferedReader.readLine(); User user = iUserService.selectUserById(Integer.parseInt(id)); System.out.println("请输入你想记录的内容"); String content = bufferedReader.readLine(); List<Note> noteListById = noteController.selectNoteById(Integer.parseInt(id)); List<Note> noteList = noteController.selectNote(); if(noteList==null&¬eListById==null){ if (user == null) { System.out.println("用户不存在"); } else { Note note = new Note(user.getName(), Integer.parseInt(id), 1, 1, content); noteController.insetNote(note); } }else if(noteListById==null) { if (user == null) { System.out.println("用户不存在"); } else { Note note = new Note(user.getName(), Integer.parseInt(id), noteList.size() + 1, 1, content); noteController.insetNote(note); } }else { if (user == null) { System.out.println("用户不存在"); } else { System.out.println(user); System.out.println(noteList); System.out.println(noteListById); Note note = new Note(user.getName(), Integer.parseInt(id), noteList.size() + 1, noteListById.size() + 1, content); noteController.insetNote(note); } } } catch (IOException e) { e.printStackTrace(); } } public void deleteNote() { System.out.println("欢迎进入删除笔记界面"); System.out.println("请输入您想删除笔记的用户id"); try { System.out.println("请输入您想删除的序号"); String sign = bufferedReader.readLine(); noteController.deleteNote(Integer.parseInt(id), Integer.parseInt(sign)); } catch (IOException e) { e.printStackTrace(); } } public void updateNote() { System.out.println("欢迎进入更改笔记界面"); System.out.println("请输入需要更改笔记的用户id"); try { id = bufferedReader.readLine(); } catch (IOException e) { e.printStackTrace(); } System.out.println("请输入需要修改的内容"); String content; try { content = bufferedReader.readLine(); List<Note> noteListById = noteController.selectNoteById(Integer.parseInt(id)); List<Note> noteList = noteController.selectNote(); IUserService iUserService = new UserServiceImpl(); User user = iUserService.selectUserById(Integer.parseInt(id)); if (user == null) { System.out.println("用户不存在"); } else { Note note = new Note(user.getName(), Integer.parseInt(id), noteList.size(), noteListById.size(), content); } } catch (IOException e) { e.printStackTrace(); } } public boolean selectNoteById() { System.out.println("欢迎进入笔记查询界面"); System.out.println("请输入您要查询笔记的用户id"); String id = null; try { id = bufferedReader.readLine(); System.out.println("查询结果如下"); List<Note> noteList = noteController.selectNoteById(Integer.parseInt(id)); if (noteList==null) { System.out.println("用户无笔记存在"); return true; } else { for (int i = 0; i < noteList.size(); i++) { System.out.println(noteList.get(i)); } } } catch(IOException e){ e.printStackTrace(); } return true; } public boolean selectNote() { System.out.println("欢迎进入笔记查询界面"); System.out.println("查询结果如下"); List<Note> noteList = noteController.selectNote(); for (int i = 0; i < noteList.size(); i++) { System.out.println(noteList.get(i)); } return true; } } //SeparationView层 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * @Author: Re * @Date: 2020/12/16 0:09 */ public class Separation { BufferedReader bufferedReader = null; public void separation() { NoteView noteView = new NoteView(); QuestionsView questionsView = new QuestionsView(); UserView userView = new UserView(); boolean symbolUser = false; boolean symbolAdministrator = false; boolean re0 = true; while (re0) { System.out.println("*********请选择页面进入*********"); System.out.println("1.注册 2.登录 3.管理员登录 4.退出系统"); bufferedReader = new BufferedReader(new InputStreamReader(System.in)); String chioce = null; try { chioce = bufferedReader.readLine(); } catch (IOException e) { e.printStackTrace(); } switch (chioce) { case "1": userView.registUser(); re0 = false; break; case "2": symbolUser = userView.loginUser(); re0 = !symbolUser; break; case "3": symbolAdministrator = userView.loginAdministrator(); re0 = !symbolAdministrator; break; case "4": re0 = false; break; default: System.out.println("您输入的数据有误"); } } if (symbolUser) { boolean re = true; boolean symbolQuestion = false; boolean symbolNote = false; while (re) { System.out.println("*********请选择页面进入*********"); System.out.println("1.更改用户信息 2.查询用户信息 3.进入题库 4. 查看笔记 5.退出程序"); String chioceSecond = null; try { chioceSecond = bufferedReader.readLine(); } catch (IOException e) { e.printStackTrace(); } switch (chioceSecond) { case "1": userView.updateUser(); break; case "2": userView.selectUserById(); break; case "3": symbolQuestion = true; break; case "4": symbolNote = noteView.selectNoteById(); break; case "5": re = false; break; default: System.out.println("您输入的数据有误"); break; } if (symbolQuestion) { System.out.println("欢迎进入题库"); System.out.println("*********请选择页面进入*********"); System.out.println("请输入您想查找的题目类型"); System.out.println("类型可分为 Math,English,Thought,HighLevelLanguage。"); String type = null; String sign= null; boolean re1=true; try { while (re1) { type = bufferedReader.readLine(); if(type.equals("Math")||type.equals("English")||type.equals("Thought")||type.equals("HighLevelLanguage")){ re1=false; }else { System.out.println("输入错误,请重新输入"); } } System.out.println("请输入需要查找的题目序号"); sign= bufferedReader.readLine(); } catch (IOException e) { e.printStackTrace(); } questionsView.selectQuestion(Integer.parseInt(sign),type); System.out.println("是否查看该题答案"); System.out.println("1. 是 2.返回主界面"); try { chioceSecond=bufferedReader.readLine(); switch (chioceSecond){ case "1": questionsView.selectAnswer(Integer.parseInt(sign),type); break; case "2": break; default: System.out.println("输入的数据有误"); break; } } catch (IOException e) { e.printStackTrace(); } } symbolQuestion = false; if (symbolNote) { System.out.println("*********请选择页面进入*********"); System.out.println("1.增加笔记 2.删除笔记 3.更改笔记 4.查看笔记 5.退出程序"); String chioceForth = null; try { chioceForth = bufferedReader.readLine(); } catch (IOException e) { e.printStackTrace(); } switch (chioceForth) { case "1": noteView.insetNote(); break; case "2": noteView.deleteNote(); break; case "3": noteView.updateNote(); break; case "4": noteView.selectNoteById(); break; case "5": re = false; break; default: System.out.println("您输入的数据有误"); break; } } symbolNote=false; } } if (symbolAdministrator) { boolean re = true; boolean symbolQuestion = false; boolean symbolNote = false; while (re) { System.out.println("*********请选择页面进入*********"); System.out.println("1.增添用户 2.查看所有用户信息 3更改管理员信息 4.根据账号删除用户 5.进入题库 6.查看用户笔记 7.退出程序"); BufferedReader bufferedReaderSecond = new BufferedReader(new InputStreamReader(System.in)); String chioceSecond = null; try { chioceSecond = bufferedReaderSecond.readLine(); } catch (IOException e) { e.printStackTrace(); } switch (chioceSecond) { case "1": userView.insertUser(); break; case "2": userView.selectUser(); break; case "3": userView.updateUser(); break; case "4": userView.deleteUserById(); break; case "5": symbolQuestion = true; break; case "6": symbolNote = noteView.selectNote(); break; case "7": re = false; break; default: System.out.println("您输入的数据有误"); break; } if (symbolQuestion) { System.out.println("欢迎进入题库"); System.out.println("*********请选择页面进入*********"); System.out.println("请输入您想查看的题目类型"); System.out.println("类型可分为 Math,English,Thought,HighLevelLanguage。"); String type = null; boolean re2=true; try { while (re2) { type = bufferedReaderSecond.readLine(); if (type.equals("Math")||type.equals("English")||type.equals("Thought")||type.equals("HighLevelLanguage")) { re2=false; }else{ System.out.println("输入错误,请重新输入"); } } } catch (IOException e) { e.printStackTrace(); } System.out.println("欢迎进入"+type+"题库"); questionsView.selectQuestions(type); System.out.println("*********请选择页面进入*********"); System.out.println("1.再次查找----------2.增加题目---------3.删除题目-----------4.更改题目---------6.退出程序"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); String chioceThird = null; try { chioceThird = bufferedReader.readLine(); } catch (IOException e) { e.printStackTrace(); } switch (chioceThird) { case "1": questionsView.selectQuestions(type); break; case "2": questionsView.insetQuestion(); break; case "3": questionsView.deleteQuestion(); break; case "4": questionsView.updateQuestion(); break; case "5": re = false; break; default: System.out.println("你输入的数据有误"); } } symbolQuestion=false; if (symbolNote) { System.out.println("*********请选择页面进入*********"); System.out.println("1.增加笔记 2.删除笔记 3.更改笔记 4.查看笔记 5.退出程序"); String chioceForth = null; try { chioceForth = bufferedReaderSecond.readLine(); } catch (IOException e) { e.printStackTrace(); } switch (chioceForth) { case "1": noteView.insetNote(); break; case "2": noteView.deleteNote(); break; case "3": noteView.updateNote(); break; case "4": noteView.selectNoteById(); break; case "5": re = false; break; default: System.out.println("您输入的数据有误"); break; } } symbolNote=false; } } } }
Utils
//Creat import java.io.IOException; /** * @author Ding * @date 2019/11/23 19:55 */ public class Create { public static void main(String[] args) throws IOException { CreateFileName createFileName=new CreateFileName(); CreatePathName createPathName=new CreatePathName(); createPathName.create("QuestionBankManagementSystem"); createPathName.create("QuestionBankManagementSystem\\Questions"); createFileName.create("QuestionBankManagementSystem\\Note.txt"); createFileName.create("QuestionBankManagementSystem\\Questions\\Math.txt"); createFileName.create("QuestionBankManagementSystem\\Questions\\English.txt"); createFileName.create("QuestionBankManagementSystem\\Questions\\Thought.txt"); createFileName.create("QuestionBankManagementSystem\\Questions\\HighLevelLanguage.txt"); createFileName.create("QuestionBankManagementSystem\\User.txt"); } } //CreateFileName import java.io.File; import java.io.IOException; /** * @author Ding * @date 2019/11/23 19:54 */ public class CreateFileName { /** * 创建文件 * @param filename * @return boolean * @throws IOException */ public boolean create(String filename) throws IOException { File file = new File(filename); file.createNewFile(); if (file.exists()) { return false; } if (file.createNewFile()) { return true; } else { return false; } } } //CreatePathName import java.io.File; import java.io.IOException; /** * @author Ding * @date 2019/11/23 19:53 */ public class CreatePathName { /** * 创建目录 * @param Filename * @return boolean * @throws IOException */ public boolean create(String Filename) throws IOException { 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; } } }
Main
import studio.lyl.questionbankmanagementsystem.view.*; /** * @Author: Re * @Date: 2020/12/7 22:36 */ public class QuestionBankManagementSystem { public static void main(String[] args) { Separation separation=new Separation(); separation.separation(); } }
总结
总的来说,这次小组的考核题虽然难,但好在给的时间挺长的,所以我才能好好的完善项目,虽然还有缺点,但我满足了。
这个项目我还认识了个大哥“空指针异常”,真是噩梦。