Java---题库管理系统(小项目)(一)

简介: Java---题库管理系统(小项目)

项目策划书

题库管理系统

一.项目设计分析

该项目可以帮助莘莘学子寻找到需要的题目,同时可以打笔记使做题效率更高.

二.项目功能简介

<1>分级管理功能:该项目实现了管理员与用户的分离,管理员和用户权限不同.

<2>注册功能:用户在登陆界面可以进行账号的注册.

<3>修改用户信息功能:当用户或管理员登录系统时,可以完成自己的密码和昵称修改.

<4>查看题目功能:用户可根据类型和题目的序号对题目进行查看.

<5>记录笔记功能:当用户做题有所收获或见解时可以通过打笔记的方法记录自己的想法.

<6>删除笔记功能:防止自己打错笔记,避免不必要的资源浪费,同时使用户拥有一个较为整洁的笔记本.

<7>监察功能:管理员对用户的拥有增删改查的权力,防止恶意注册账号等

代码

实体

/**
 * @Author: Re
 * @Date: 2020/12/7 15:31
 * 用户实体
 */
public class User implements Comparable<User>{
    private Integer id;
    private int level;
    private String password;
    private String userName;
    private int nodeCount;
    private String node;
    private int collectionCount;
    public String getUserName() {
        return userName;
    }
    public String getNode() {
        return node;
    }
    public void setNode(String node) {
        this.node = node;
    }
    public int getLevel() {
        return level;
    }
    public User() {
    }
    public User(Integer id)
    {
        this.id = id;
    }
    public User(Integer id,String password,String userName,int nodeCount,int collectionCount,int level) {
        this.id=id;
        this.password = password;
        this.userName = userName;
        this.level=level;
        this.nodeCount=nodeCount;
        this.collectionCount=collectionCount;
    }
    public int getId() {
        return id;
    }
    public void setId(Integer id)
    {
        this.id = id;
    }
    public String getPassword() {
        return password;
    }
    public int getNodeCount() {
        return nodeCount;
    }
    public void setNodeCount(int nodeCount) {
        this.nodeCount = nodeCount;
    }
    public int getCollectionCount() {
        return collectionCount;
    }
    public String getName() {
        return userName;
    }
    public void setName(String userName) {
        this.userName = userName;
    }
    @Override
    public String toString() {
        String s= (this.level==1)? "管理员":"用户";
        return  "账号为:" + this.id +
                ",用户名为: " + this.userName +
                ",身份:  "+ s;
    }
    /**
     * 比较器,用于用户的排序
     * @param o
     * @return
     */
    @Override
    public int compareTo(User o) {
        if(this.getId()==o.getId()){
            return this.getName().compareTo(o.getName());
        }else if(this.getId()>o.getId()){
            return 1;
        }
        return -1;
    }
}
import java.util.Objects;
/**
 * @Author: Re
 * @Date: 2020/12/7 15:46
 * 问题实体
 */
public class Questions implements Comparable<Questions>{
    private String content;
    private String type;
    private int sign;
    private String complexity;
    private String answer;
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getComplexity()
    {
        return complexity;
    }
    public String getAnswer() {
        return answer;
    }
    public void setAnswer(String answer) {
        this.answer = answer;
    }
    public Questions() {
    }
    public Questions(String content, String type, int sign, String complexity, String answer) {
        this.content = content;
        this.type = type;
        this.sign = sign;
        this.complexity = complexity;
        this.answer = answer;
    }
    public String getContent() {
        return content;
    }
    public int getSign() {
        return sign;
    }
    public void setSign(int sign) {
        this.sign = sign;
    }
    @Override
    public String toString() {
        return "序号:" + sign+
                "--题目类型:" + type  +
                "--难易程度:" + complexity+
                "\n"+content+"?"
                ;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Questions questions = (Questions) o;
        return complexity == questions.complexity &&
                Objects.equals(type, questions.type) &&
                Objects.equals(sign, questions.sign);
    }
    /**
     * 比较器,用于题目的排序
     * @param o
     * @return
     */
    @Override
    public int compareTo(Questions o) {
        if(this.getSign()==o.getSign()){
            return this.getType().compareTo(o.getType());
        }else if(this.getSign()>o.getSign()){
            return 1;
        }else {
            return -1;
        }
    }
}
import java.util.Date;
/**
 * @Author: Re
 * @Date: 2020/12/7 17:55
 * 笔记实体
 */
public class Note implements Comparable<Note>{
    private Date time;
    private String master;
    private Integer id;
    private Integer Count=0;
    private Integer sign=0;
    private String Content;
    public Note() {
    }
    public Note(String maser) {
        this.master = maser;
    }
    public int getSign() {
        return sign;
    }
    public void setSign(Integer sign) {
        this.sign = sign;
    }
    public Date getTime() {
        return time;
    }
    public void setTime(Date time) {
        this.time = time;
    }
    public String getMaster() {
        return master;
    }
    public int getCount() {
        return Count;
    }
    public Integer getId() {
        return id;
    }
    public String getContent() {
        return Content;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public Note( String master, Integer id, Integer count, Integer sign, String content) {
        this.master = master;
        this.id = id;
        Count = count;
        this.sign = sign;
        Content = content;
    }
    @Override
    public String toString() {
        return  "笔记内容:"+getContent() +
                "\n               用户名:" + master  +
                " 笔记数目:" + Count ;
    }
    /**
     * 用于存入笔记的排序
     * @param o
     * @return
     */
    @Override
    public int compareTo(Note o) {
        if(this.getId().equals(o.getId())){
            return this.getSign()-o.getSign();
        }else if(this.getId() > o.getId()){
            return 1;
        }
        return -1;
    }
}

Dao

接口

//用户dao层接口
import studio.lyl.questionbankmanagementsystem.entity.User;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2020/12/7 16:23
 */
public interface IUserDao {
    /**
     * 创建用户
     * @param user
     * @return boolean
     */
    boolean insertUser(User user) ;
    /**
     * 根据id删除用户
     * @param id
     * @return boolean
     */
    boolean deleteUserById(Integer id) ;
    /**
     * 修改用户信息
     * @param id
     * @param user
     * @return boolean
     */
    boolean updateUser(Integer id,User user) ;
    /**
     * 根据id查看用户信息
     * @param id
     * @return List
     */
    List<User> selectUserById(Integer id) ;
    /**
     * 查看所有用户信息
     * @return
     * @throws Exception
     */
    List<User> selectUser() ;
}
//题库dao层接口
import studio.lyl.questionbankmanagementsystem.entity.Questions;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2020/12/7 17:15
 */
public interface IQuestionDao{
    /**
     * 增加题目
     * @param questions
     * @return boolean
     */
    boolean insetQuestion(Questions questions) throws Exception;
    /**
     * 根据序号删除题目
     * @param sign
     * @param type
     * @return boolean
     */
    boolean deleteQuestion(int sign,String type) throws Exception;
    /**
     * 根据序号删除题目
     * @param sign
     * @param questions
     * @param type
     * @return
     */
    boolean updateQuestion(int sign ,String type ,Questions questions) throws Exception;
    /**
     * 根据序号查看题目
     * @param sign
     * @param type
     * @return String
     */
    List<Questions> selectQuestion(int sign, String type) ;
    /**
     * 根据序号和类型查看一个题的答案
     * @param sign
     * @param type
     * @return
     */
    List<Questions> selectAnswer(int sign,String type) ;
    /**
     * 查看一个类型里所有的题目
     * @param type
     * @return List
     * @throws Exception
     */
    List<Questions> selectQuestions(String type) ;
}
//笔记dao层窗口
import studio.lyl.questionbankmanagementsystem.entity.Note;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2020/12/7 18:13
 */
public interface INoteDao {
    /**
     * 增加笔记
     * @param note
     * @return boolean
     */
    boolean insetNote(Note note) ;
    /**
     * 根据用户id删除笔记
     * @param id
     * @return boolean
     */
    boolean deleteNote(Integer id,Integer sign) ;
    /**
     * 根据用户id更改笔记
     * @param id
     * @param note
     * @param sign
     * @return
     */
    boolean updateNote(Integer id,Integer sign,Note note) ;
    /**
     * 根据用户id查看笔记
     * @param id
     * @return
     */
    List<Note> selectNoteById(Integer id) ;
    /**
     * 查看所有的笔记
     * @return
     */
    List<Note> selectNote() ;
}

实现接口

//用户dao层接口实现
```import studio.lyl.questionbankmanagementsystem.dao.IUserDao;
import studio.lyl.questionbankmanagementsystem.entity.User;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2020/12/8 22:12
 */
public class UserDaoImpl implements IUserDao {
    @Override
    public boolean insertUser(User user)  {
        try {
            BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\User.txt",true));
            String returnString=String.format("%s,%s,%s,%s,%s,%s",user.getId(),user.getPassword(),user.getUserName(),0,0,0);
            bufferedWriter.write(returnString);
            bufferedWriter.newLine();
            bufferedWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
    @Override
    public boolean deleteUserById(Integer id) {
        BufferedReader bufferedReader= null;
        try {
            bufferedReader = new BufferedReader(new FileReader("QuestionBankManagementSystem\\User.txt"));
            List<User> userList=new ArrayList<>();
            String s=null;
            while ((s=bufferedReader.readLine())!=null){
                String[] strings=s.split(",");
                User user=new User(Integer.parseInt(strings[0]),strings[1],strings[2],Integer.parseInt(strings[3]),Integer.parseInt(strings[4]),Integer.parseInt(strings[5]));
                userList.add(user);
            }
            for (int i = 0; i < userList.size(); i++) {
                User userGet=userList.get(i);
                if(userGet.getId()==id) {
                    userList.remove(i);
                }
            }
            Collections.sort(userList);
            BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\User.txt"));
            for (int i = 0; i < userList.size(); i++) {
                User user=userList.get(i);
                String returnString=String.format("%s,%s,%s,%s,%s,%s",user.getId(),user.getPassword(),user.getUserName(),user.getNodeCount(),user.getCollectionCount(),user.getLevel());
                bufferedWriter.write(returnString);
                bufferedWriter.newLine();
            }
            bufferedReader.close();
            bufferedWriter.flush();
            bufferedReader.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
    @Override
    public boolean updateUser(Integer id,User user)  {
        BufferedReader bufferedReader= null;
        try {
            bufferedReader = new BufferedReader(new FileReader("QuestionBankManagementSystem\\User.txt"));
            List<User> userList=new ArrayList<>();
            String s=null;
            while ((s=bufferedReader.readLine())!=null){
                String[] strings=s.split(",");
                User userGet=new User(Integer.parseInt(strings[0]),strings[1],strings[2],Integer.parseInt(strings[3]),Integer.parseInt(strings[4]),Integer.parseInt(strings[5]));
                userList.add(userGet);
            }
            for (int i = 0; i < userList.size(); i++) {
                User userGet=userList.get(i);
                if(userGet.getId()==id) {
                    userList.set(i,user);
                }
            }
            Collections.sort(userList);
            BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\User.txt"));
            for (int i = 0; i < userList.size(); i++) {
                User userGet=userList.get(i);
                String returnString=String.format("%s,%s,%s,%s,%s,%s",userGet.getId(),userGet.getPassword(),userGet.getUserName(),userGet.getNodeCount(),userGet.getCollectionCount(),userGet.getLevel());
                bufferedWriter.write(returnString);
                bufferedWriter.newLine();
            }
            bufferedReader.close();
            bufferedWriter.flush();
            bufferedReader.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
    @Override
    public List<User> selectUserById(Integer id) {
        BufferedReader bufferedReader= null;
        List<User> returnUserList=new ArrayList<>();
        try {
            bufferedReader = new BufferedReader(new FileReader("QuestionBankManagementSystem\\User.txt"));
            List<User> userList=new ArrayList<>();
            String s=null;
            while ((s=bufferedReader.readLine())!=null){
                String[] strings=s.split(",");
                User user=new User(Integer.parseInt(strings[0]),strings[1],strings[2],Integer.parseInt(strings[3]),Integer.parseInt(strings[4]),Integer.parseInt(strings[5]));
                userList.add(user);
            }
            for (int i = 0; i < userList.size(); i++) {
                User user=userList.get(i);
                if(user.getId()==id){
                    returnUserList.add(user);
                }
            }
            Collections.sort(returnUserList);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return returnUserList;
    }
    @Override
    public List<User> selectUser() {
        BufferedReader bufferedReader= null;
        List<User> userList=new ArrayList<>();
        try {
            bufferedReader = new BufferedReader(new FileReader("QuestionBankManagementSystem\\User.txt"));
            String s=null;
            while ((s=bufferedReader.readLine())!=null){
                String[] strings=s.split(",");
                User user=new User(Integer.parseInt(strings[0]),strings[1],strings[2],Integer.parseInt(strings[3]),Integer.parseInt(strings[4]),Integer.parseInt(strings[5]));
                userList.add(user);
            }
            Collections.sort(userList);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return userList;
    }
}
//题库dao层实现
import studio.lyl.questionbankmanagementsystem.dao.IQuestionDao;
import studio.lyl.questionbankmanagementsystem.entity.Questions;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2020/12/8 20:18
 */
public class QuestionDaoImpl implements IQuestionDao {
    @Override
    public boolean insetQuestion(Questions questions) {
        BufferedWriter bufferedWriter= null;
        try {
            bufferedWriter = new BufferedWriter(new FileWriter(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+questions.getType()+".txt",true));
            bufferedWriter.write(questions.getContent()+","+questions.getType()+","+questions.getSign()+","+questions.getComplexity()+","+questions.getAnswer());
            bufferedWriter.newLine();
            bufferedWriter.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return false;
    }
    @Override
    public boolean deleteQuestion(int sign,String type)  {
        BufferedReader bufferedReader= null;
        BufferedWriter bufferedWriter=null;
        try {
            bufferedReader = new BufferedReader(new FileReader(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+type+".txt"));
            List<Questions> questionsList=new ArrayList<>();
            String s;
            while ((s=bufferedReader.readLine())!=null){
                String[] strings=s.split(",");
                Questions questions=new Questions(strings[0],strings[1],Integer.parseInt(strings[2]),strings[3],strings[4]);
                questionsList.add(questions);
            }
            for (int i = 0; i < questionsList.size(); i++) {
                Questions questions=questionsList.get(i);
                if(questions.getSign()==sign){
                    questionsList.remove(i);
                }
            }
            Collections.sort(questionsList);
            bufferedWriter=new BufferedWriter(new FileWriter(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+type+".txt"));
            for (int i = 0; i < questionsList.size(); i++) {
                Questions questions=questionsList.get(i);
                String returnString=String.format("%s,%s,%s,%s,%s",questions.getContent(),questions.getType(),questions.getSign(),questions.getComplexity(),questions.getAnswer());
                bufferedWriter.write(returnString);
                bufferedWriter.newLine();
            }
            bufferedWriter.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return false;
    }
    @Override
    public boolean updateQuestion(int sign,String type,Questions questions) {
        BufferedReader bufferedReader= null;
        BufferedWriter bufferedWriter=null;
        try {
            bufferedReader = new BufferedReader(new FileReader(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+type+".txt"));
            List<Questions> questionsList=new ArrayList<>();
            String s;
            while ((s=bufferedReader.readLine())!=null){
                String[] strings=s.split(",");
                Questions questionsSet=new Questions(strings[0],strings[1],Integer.parseInt(strings[2]),strings[3],strings[4]);
                questionsList.add(questionsSet);
            }
            for (int i = 0; i < questionsList.size(); i++) {
                Questions questionsSet=questionsList.get(i);
                if(questionsSet.getSign()==sign){
                    questionsList.set(i,questions);
                }
            }
            Collections.sort(questionsList);
            bufferedWriter=new BufferedWriter(new FileWriter(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+type+".txt"));
            for (int i = 0; i < questionsList.size(); i++) {
                Questions questionsSet=questionsList.get(i);
                String returnString=String.format("%s,%s,%s,%s,%s",questionsSet.getContent(),questionsSet.getType(),questionsSet.getSign(),questionsSet.getComplexity(),questionsSet.getAnswer());
                bufferedWriter.write(returnString);
                bufferedWriter.newLine();
            }
            bufferedWriter.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                bufferedWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return false;
    }
    @Override
    public List<Questions> selectQuestion(int sign,String type)  {
        BufferedReader bufferedReader= null;
        List<Questions> returnQuestionsList=new ArrayList<>();
        try {
            bufferedReader = new BufferedReader(new FileReader(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+type+".txt"));
            List<Questions> questionsList=new ArrayList<>();
            String s;
            while ((s=bufferedReader.readLine())!=null){
                String[] strings=s.split(",");
                Questions questions=new Questions(strings[0],strings[1],Integer.parseInt(strings[2]),strings[3],strings[4]);
                questionsList.add(questions);
            }
            for (int i = 0; i < questionsList.size(); i++) {
                Questions questions=questionsList.get(i);
                if(questions.getSign()==sign){
                    for (int j = 0; j < questionsList.size(); j++) {
                        returnQuestionsList.add(questions);
                    }
                }
            }
            Collections.sort(returnQuestionsList);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return returnQuestionsList;
    }
    @Override
    public List<Questions> selectAnswer(int sign, String type) {
        BufferedReader bufferedReader= null;
        try {
            bufferedReader = new BufferedReader(new FileReader(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+type+".txt"));
            List<Questions> questionsList=new ArrayList<>();
            String s=null;
            while ((s=bufferedReader.readLine())!=null){
                String[] strings=s.split(",");
                Questions questions=new Questions(strings[0],strings[1],Integer.parseInt(strings[2]),strings[3],strings[4]);
                questionsList.add(questions);
            }
            for (int i = 0; i < questionsList.size(); i++) {
                Questions questions=questionsList.get(i);
                if(questions.getSign()==sign){
                    System.out.println(questions.getAnswer());
                }
            }
            Collections.sort(questionsList);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
    @Override
    public List<Questions> selectQuestions(String type) {
        BufferedReader bufferedReader=null;
        List<Questions> questionsList=null;
        try {
            bufferedReader = new BufferedReader(new FileReader(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+type+".txt"));
            questionsList=new ArrayList<>();
            String s=null;
            while ((s=bufferedReader.readLine())!=null){
                String[] strings=s.split(",");
                Questions questions=new Questions(strings[0],strings[1],Integer.parseInt(strings[2]),strings[3],strings[4]);
                questionsList.add(questions);
            }
            Collections.sort(questionsList);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return questionsList;
    }
}
//笔记dao层实现
import studio.lyl.questionbankmanagementsystem.dao.INoteDao;
import studio.lyl.questionbankmanagementsystem.dao.IUserDao;
import studio.lyl.questionbankmanagementsystem.entity.Note;
import studio.lyl.questionbankmanagementsystem.entity.User;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2020/12/8 8:37
 */
public class NoteDaoImpl implements INoteDao  {
    @Override
    public boolean insetNote(Note note) {
        BufferedWriter bufferedWriter= null;
        IUserDao iUserDao=new UserDaoImpl();
        try {
            List<User> userList=iUserDao.selectUserById(note.getId());
            User user=userList.get(0);
            user.setNodeCount(user.getCollectionCount()+1);
            bufferedWriter = new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\Note.txt",true));
            bufferedWriter.write(note.getMaster()+","+note.getId()+","+note.getCount()+","+note.getSign()+","+note.getContent());
            bufferedWriter.newLine();
            bufferedWriter.flush();;
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
            return false;
    }
        @Override
        public boolean deleteNote(Integer id,Integer sign) {
        BufferedReader bufferedReader= null;
        BufferedWriter bufferedWriter=null;
        try {
            bufferedReader = new BufferedReader(new FileReader("QuestionBankManagementSystem\\Note.txt"));
            List<Note> noteList=new ArrayList<>();
            String s;
            while ((s=bufferedReader.readLine())!=null){
                String[] strings=s.split(",");
                Note note=new Note(strings[0],Integer.parseInt(strings[1]),Integer.parseInt(strings[2]),Integer.parseInt(strings[3]),strings[4]);
                noteList.add(note);
            }
            bufferedWriter=new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\Note.txt"));
            for (int i = 0; i < noteList.size(); i++) {
                Note note=noteList.get(i);
                if(note.getId().equals(id)){
                    if (note.getSign()==sign){
                        noteList.remove(i);
                    }
                }
            }
            Collections.sort(noteList);
            for (int i = 0; i < noteList.size(); i++) {
                Note note=noteList.get(i);
                String returnString=String.format("%s,%s,%s,%s,%s",note.getMaster(),note.getId(),note.getCount(),note.getSign(),note.getContent());
                bufferedWriter.write(returnString);
                bufferedWriter.newLine();
            }
            bufferedWriter.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return false;
    }
    @Override
    public boolean updateNote(Integer id,Integer sign,Note note) {
        BufferedReader bufferedReader= null;
        BufferedWriter bufferedWriter=null;
        try {
            bufferedReader = new BufferedReader(new FileReader("QuestionBankManagementSystem\\Note.txt"));
            List<Note> noteList=new ArrayList<>();
            String s;
            while ((s=bufferedReader.readLine())!=null){
                String[] strings=s.split(",");
                Note noteGet=new Note(strings[0],Integer.parseInt(strings[1]),Integer.parseInt(strings[2]),Integer.parseInt(strings[3]),strings[4]);
                noteList.add(noteGet);
            }
            bufferedWriter=new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\Note.txt"));
            for (int i = 0; i < noteList.size(); i++) {
                Note noteSet=noteList.get(i);
                if(noteSet.getId().equals(id)) {
                    if(noteSet.getSign()==sign) {
                        noteList.set(sign-1, note);
                    }
                }
            }
            Collections.sort(noteList);
            for (int i = 0; i < noteList.size(); i++) {
                Note returnNote=noteList.get(i);
                    String returnString = String.format("%s,%s,%s,%s,%s", returnNote.getMaster(), returnNote.getId(), returnNote.getCount(), returnNote.getSign(), returnNote.getContent());
                    bufferedWriter.write(returnString);
                    bufferedWriter.newLine();
            }
            bufferedWriter.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return false;
    }
    @Override
    public List<Note> selectNoteById(Integer id) {
        BufferedReader bufferedReader= null;
        List<Note> returnNoteList=new ArrayList<>();
        try {
            bufferedReader = new BufferedReader(new FileReader("QuestionBankManagementSystem\\Note.txt"));
            List<Note> noteList=new ArrayList<>();
            String s;
            while ((s=bufferedReader.readLine())!=null){
                String[] strings=s.split(",");
                Note note=new Note(strings[0],Integer.parseInt(strings[1]),Integer.parseInt(strings[2]),Integer.parseInt(strings[3]),strings[4]);
                noteList.add(note);
            }
            for (int i = 0; i < noteList.size(); i++) {
                Note note=noteList.get(i);
                if(note.getId().equals(id)){
                   returnNoteList.add(note);
                }
            }
            Collections.sort(returnNoteList);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return returnNoteList;
    }
    @Override
    public List<Note> selectNote() {
        BufferedReader bufferedReader= null;
        List<Note> noteList=new ArrayList<>();
        try {
            bufferedReader = new BufferedReader(new FileReader("QuestionBankManagementSystem\\Note.txt"));
            String s;
            while ((s=bufferedReader.readLine())!=null){
                String[] strings=s.split(",");
                Note note=new Note(strings[0],Integer.parseInt(strings[1]),Integer.parseInt(strings[2]),Integer.parseInt(strings[3]),strings[4]);
                noteList.add(note);
            }
            Collections.sort(noteList);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return noteList;
    }
}


相关文章
|
25天前
|
监控 Java API
如何使用Java语言快速开发一套智慧工地系统
使用Java开发智慧工地系统,采用Spring Cloud微服务架构和前后端分离设计,结合MySQL、MongoDB数据库及RESTful API,集成人脸识别、视频监控、设备与环境监测等功能模块,运用Spark/Flink处理大数据,ECharts/AntV G2实现数据可视化,确保系统安全与性能,采用敏捷开发模式,提供详尽文档与用户培训,支持云部署与容器化管理,快速构建高效、灵活的智慧工地解决方案。
|
7天前
|
NoSQL Java 关系型数据库
Liunx部署java项目Tomcat、Redis、Mysql教程
本文详细介绍了如何在 Linux 服务器上安装和配置 Tomcat、MySQL 和 Redis,并部署 Java 项目。通过这些步骤,您可以搭建一个高效稳定的 Java 应用运行环境。希望本文能为您在实际操作中提供有价值的参考。
60 26
|
19天前
|
XML Java 测试技术
从零开始学 Maven:简化 Java 项目的构建与管理
Maven 是一个由 Apache 软件基金会开发的项目管理和构建自动化工具。它主要用在 Java 项目中,但也可以用于其他类型的项目。
31 1
从零开始学 Maven:简化 Java 项目的构建与管理
|
16天前
|
设计模式 消息中间件 搜索推荐
Java 设计模式——观察者模式:从优衣库不使用新疆棉事件看系统的动态响应
【11月更文挑战第17天】观察者模式是一种行为设计模式,定义了一对多的依赖关系,使多个观察者对象能直接监听并响应某一主题对象的状态变化。本文介绍了观察者模式的基本概念、商业系统中的应用实例,如优衣库事件中各相关方的动态响应,以及模式的优势和实际系统设计中的应用建议,包括事件驱动架构和消息队列的使用。
|
18天前
|
Java
Java项目中高精度数值计算:为何BigDecimal优于Double
在Java项目开发中,涉及金额计算、面积计算等高精度数值操作时,应选择 `BigDecimal` 而非 `Double`。`BigDecimal` 提供任意精度的小数运算、多种舍入模式和良好的可读性,确保计算结果的准确性和可靠性。例如,在金额计算中,`BigDecimal` 可以精确到小数点后两位,而 `Double` 可能因精度问题导致结果不准确。
|
28天前
|
Java Android开发
Eclipse 创建 Java 项目
Eclipse 创建 Java 项目
39 4
|
1月前
|
SQL Java 数据库连接
从理论到实践:Hibernate与JPA在Java项目中的实际应用
本文介绍了Java持久层框架Hibernate和JPA的基本概念及其在具体项目中的应用。通过一个在线书店系统的实例,展示了如何使用@Entity注解定义实体类、通过Spring Data JPA定义仓库接口、在服务层调用方法进行数据库操作,以及使用JPQL编写自定义查询和管理事务。这些技术不仅简化了数据库操作,还显著提升了开发效率。
42 3
|
1月前
|
运维 自然语言处理 供应链
Java云HIS医院管理系统源码 病案管理、医保业务、门诊、住院、电子病历编辑器
通过门诊的申请,或者直接住院登记,通过”护士工作站“分配患者,完成后,进入医生患者列表,医生对应开具”长期医嘱“和”临时医嘱“,并在电子病历中,记录病情。病人出院时,停止长期医嘱,开具出院医嘱。进入出院审核,审核医嘱与住院通过后,病人结清缴费,完成出院。
81 3
|
1月前
|
前端开发 Java 数据库
如何实现一个项目,小白做项目-java
本教程涵盖了从数据库到AJAX的多个知识点,并详细介绍了项目实现过程,包括静态页面分析、数据库创建、项目结构搭建、JSP转换及各层代码编写。最后,通过通用分页和优化Servlet来提升代码质量。
48 1
|
1月前
|
Java 数据库连接 数据库
深入探讨Java连接池技术如何通过复用数据库连接、减少连接建立和断开的开销,从而显著提升系统性能
在Java应用开发中,数据库操作常成为性能瓶颈。本文通过问题解答形式,深入探讨Java连接池技术如何通过复用数据库连接、减少连接建立和断开的开销,从而显著提升系统性能。文章介绍了连接池的优势、选择和使用方法,以及优化配置的技巧。
31 1