文章目录

  • 前言
  • 一、工程文件
  • 二、Book.java
  • 三、BookType.java
  • 四、BorrowBook.java
  • 五、Reader.java
  • 六、ReaderType.java
  • 七、Users.java
  • 八、Test.java
  • 九、总结



前言


【项目说明】
长期以来,人们使用传统的人工方式管理图书馆的日常业务,其操作流程比较烦琐。所以,我们需求设计一个图书管理系统来方便学生的借书和图书馆管理书籍。

【项目内容】

项目功能结构图:

java 图书馆 java图书馆管理系统源代码_java 图书馆


一、工程文件


文件目录:

java 图书馆 java图书馆管理系统源代码_System_02

二、Book.java

图书的基本信息
代码如下:

private static String ISBN;//图书编号ISBN
    private String bookname;//图书名称
    private String author;//作者
    private String publish;//出版社
    private String pubilishdate;//出版日期
    private String printtime;//印刷次数
    private String unitprice;//单价

    public Book() {
    }

    public Book(String ISBN, String bookname, String author, String publish, String pubilishdate, String printtime, String unitprice) {
        this.ISBN = ISBN;
        this.bookname = bookname;
        this.author = author;
        this.publish = publish;
        this.pubilishdate = pubilishdate;
        this.printtime = printtime;
        this.unitprice = unitprice;
    }

    public String getISBN() {
        return ISBN;
    }

    public void setISBN(String ISBN) {
        this.ISBN = ISBN;
    }

    public String getBookname() {
        return bookname;
    }

    public void setBookname(String bookname) {
        this.bookname = bookname;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getPublish() {
        return publish;
    }

    public void setPublish(String publish) {
        this.publish = publish;
    }

    public String getPubilishdate() {
        return pubilishdate;
    }

    public void setPubilishdate(String pubilishdate) {
        this.pubilishdate = pubilishdate;
    }

    public String getPrinttime() {
        return printtime;
    }

    public void setPrinttime(String printtime) {
        this.printtime = printtime;
    }

    public String getUnitprice() {
        return unitprice;
    }

    public void setUnitprice(String unitprice) {
        this.unitprice = unitprice;
    }

    @Override
    public String toString() {
        return  ISBN +
                "," + bookname +
                "," + author +
                "," + publish +
                "," + pubilishdate +
                "," + printtime +
                "," + unitprice
                ;
    }

图书的增删改查方法
代码如下:

//删除图书信息
    public static void deleteBook() {
        try {
            FileReader f2 = new FileReader("book.txt");
            int x=0;
            char[] chars = new char[50];
            if (( x= f2.read(chars))==-1){
                System.out.println("图书信息为空请先添加!!!");
                return;
            }
            f2.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        ArrayList<String> arrayBook = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要删除的图书编号:");
        String s = scanner.next();
        try {
            BufferedReader b1 = new BufferedReader(new FileReader("book.txt"));
            String x;
            while ((x=b1.readLine())!=null){
                arrayBook.add(x);
            }
//            System.out.println(arrayBook);
            b1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String[] chars = new String[9];
        boolean flag = false;
        for (String s1:arrayBook){
            chars=s1.split(",");
            if (chars[0].equals(s)){
                flag=true;
            }
        }
        if(!flag) {
            System.out.println("输入的图书编号不存在!!!");
            return;
        }
        ArrayList<String> borrowBook = new ArrayList<>();
        try {
            BufferedReader b2 = new BufferedReader(new FileReader("borrowbook.txt"));
            String x;
            while ((x=b2.readLine())!=null){
                borrowBook.add(x);
            }
            b2.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String[] chars1 = new String[5];
        for (String a:borrowBook){
            chars1=a.split(",");
            if (chars1[1].equals(s)) {
                System.out.println("该图书已被读者借去,还未归还,不能删除!!!");
                return;
            }
        }
        String[] b = new String[9];
        Iterator iterator = arrayBook.iterator();
        while (iterator.hasNext()){
            String s1 = (String) iterator.next();
            b = s1.split(",");
            if (b[0].equals(s)) {
                iterator.remove();
            }
        }
        try {
            FileWriter fileWriter = new FileWriter("book.txt", false);
            StringBuffer stringBuffer = new StringBuffer();
            for(String s2 : arrayBook){
                stringBuffer.append(s2);
                stringBuffer.append("\n");
            }
            fileWriter.write(stringBuffer.toString());
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        //提示信息
        System.out.println("删除图书信息成功");
    }
    //修改图书信息
    public static void updateReader() {
        System.out.println("请删除这本书,再添加一本书!!!");
    }

    //查看图书信息
    public static void fandAllBook() {
        try {
            FileReader f2 = new FileReader("book.txt");
            int x=0;
            char[] chars = new char[50];
            if (( x= f2.read(chars))==-1){
                System.out.println("图书信息为空请先添加!!!");
                return;
            }else {
                do {
                    System.out.print(new String(chars, 0, x));
//                    f2.read(chars);
                } while ((x = f2.read(chars)) != -1);
            }
            f2.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //添加图书信息
    public static void addBook() {
        ArrayList<String> arrayBook = new ArrayList<>();
        try {
        BufferedReader b1 = new BufferedReader(new FileReader("book.txt"));
        String x;
        while ((x=b1.readLine())!=null){
            arrayBook.add(x);
        }
            b1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入图书编号:");
        String ISBN=scanner.next();
        String[] strings = new String[9];
        for (String b:arrayBook){
            strings=b.split(",");
            if (strings[0].equals(ISBN)){
                System.out.println("该图书已存在!!!");
                return;
            }
        }
        System.out.println("请输入图书名称:");
        String bookname=scanner.next();
        System.out.println("请输入图书作者:");
        String author=scanner.next();
        System.out.println("请输入图书出版社:");
        String publish=scanner.next();
        System.out.println("请输入图书出版日期:");
        String pubilishdate=scanner.next();
        System.out.println("请输入图书印刷次数:");
        String printtime=scanner.next();
        System.out.println("请输入图书单价:");
        String unitprice=scanner.next();
        //创建读者对象
        Book book = new Book();
        book.setISBN(ISBN);
        book.setBookname(bookname);
        book.setAuthor(author);
        book.setPublish(publish);
        book.setPubilishdate(pubilishdate);
        book.setPrinttime(printtime);
        book.setUnitprice(unitprice);

        //提示信息
        System.out.println("添加图书信息成功");
        try {
            FileWriter fileWriter = new FileWriter("book.txt",true);
            fileWriter.write(book+"\n");
            fileWriter.flush();
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

三、BookType.java

图书类别的基本信息
代码如下:

public class BookType extends Book{
    private String typeid;//图书类型编号
    private String typename;//图书类型名称

    public BookType() {
    }

    public BookType(String typeid, String typename) {
        this.typeid = typeid;
        this.typename = typename;
    }

    @Override
    public String toString() {
        return typeid +
                "," + typename +
                "," + getISBN()
               ;
    }

    public String getTypeid() {
        return typeid;
    }

    public void setTypeid(String typeid) {
        this.typeid = typeid;
    }

    public String getTypename() {
        return typename;
    }

    public void setTypename(String typename) {
        this.typename = typename;
    }
}

图书类别的增删改查方法
代码如下:

public static void selectBookType() {
        ArrayList<String> bookType = new ArrayList<>();
        try {
        BufferedReader b1 = new BufferedReader(new FileReader("booktype.txt"));
        String x;
        while ((x=b1.readLine())!=null){
            bookType.add(x);
        }
            b1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要添加的图书类别编号:");
        String n=scanner.next();
        String[] chars = new String[3];
//        for (String s:bookType){
//            chars=s.split(",");
//            if (chars[0].equals(n)){
//                System.out.println("输入的图书类别编号已存在!!!");
//                return;
//            }
//        }
        System.out.println("请输入要添加的图书类别名称:");
        String m=scanner.next();
        boolean flag=true;
        for (String s:bookType){
            chars=s.split(",");
            if (chars[0].equals(n)&&chars[1].equals(m)){
              break;
            }
            if (chars[0].equals(n)){
                System.out.println("输入的图书类别编号已存在!!!");
                return;
            }
            if (chars[1].equals(m)){
                flag=false;
                break;
            }
        }
        if (!flag){
            System.out.println("输入的图书类别名称已存在!!!");
            return;
        }
        System.out.println("请输入要添加的图书类别的图书编号:");
        String b=scanner.next();
        ArrayList<String> book = new ArrayList<>();
        try {
        BufferedReader b1 = new BufferedReader(new FileReader("book.txt"));
        String x;
        while ((x=b1.readLine())!=null){
            book.add(x);
        }
            b1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        boolean falg=false;
        String[] chars1 = new String[9];
        for (String s:book){
            chars1=s.split(",");
            if (chars1[0].equals(b)){
                falg=true;
            }
        }
        if (!falg) {
            System.out.println("输入的图书编号不存在!!!");
            return;
        }
        for (String s:bookType){
            chars=s.split(",");
            if (chars[2].equals(b)){
                System.out.println("输入的图书已存在类别!!!");
                return;
            }
        }
        BookType type = new BookType();
        type.setTypeid(n);
        type.setTypename(m);
        type.setISBN(b);
        //提示信息
        System.out.println("添加图书类别成功!!!");
        try {
        FileWriter f1 = new FileWriter("booktype.txt",true);
        f1.write(type+"\n");
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //删除图书类别
    public static void deleteBookType() {
        ArrayList<String> bookType = new ArrayList<>();
        try {
        FileReader f = new FileReader("booktype.txt");
        char[] chars1 = new char[50];
        if ((f.read(chars1))==-1){
            System.out.println("图书类型为空请先添加!!!");
            return;
        }else {
            BufferedReader b1 = new BufferedReader(new FileReader("booktype.txt"));
            String x;
            while ((x=b1.readLine())!=null){
                bookType.add(x);
            }
            b1.close();
        }
            f.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要删除的图书类别编号:");
        String n=scanner.next();
        boolean flag=false;
        String[] chars = new String[3];
        Iterator<String> iterator = bookType.iterator();
        while (iterator.hasNext()){
            String s=iterator.next();
            chars=s.split(",");
            if (chars[0].equals(n)){
                iterator.remove();
                flag=true;
            }
        }
        if (!flag){
            System.out.println("输入的类别编号不存在!!!");
            return;
        }
        System.out.println("恭喜你,输入的图书类别编号删除成功!!!");
        try {
        FileWriter f1 = new FileWriter("booktype.txt",false);
        StringBuffer stringBuffer = new StringBuffer();
        for (String b:bookType){
            stringBuffer.append(b);
            stringBuffer.append("\n");
        }
        f1.write(stringBuffer.toString());
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    //修改图书类别
    public static void updateBookType() {
        System.out.println("请删除这个类型,再添加一个新类型!!!");
    }
    //查询图书类别
    public static void insertBookType() {
        try {
            FileReader f1 = new FileReader("booktype.txt");
            int i = 0;
            char[] chars = new char[3];
            if ((i = f1.read(chars)) == -1) {
                System.out.println("图书类型为空请先添加!!!");
                return;
            }
            do {
                System.out.print(new String(chars, 0, i));
            } while ((i = f1.read(chars)) != -1);
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

四、BorrowBook.java

借阅图书的基本信息
代码如下:

public class BorrowBook extends Book{
    private String readerid;//读者编号
    private String ISBN;//图书编号
    private String borrowdate;//借书日期
    private String returndate;//还书日期
    private double fine;//违约罚款

    public BorrowBook() {
    }

    public BorrowBook(String readerid, String ISBN, String borrowdate, String returndate, double fine) {
        this.readerid = readerid;
        this.ISBN = ISBN;
        this.borrowdate = borrowdate;
        this.returndate = returndate;
        this.fine = fine;
    }

    @Override
    public String toString() {
        return readerid +
                "," + ISBN +
                "," + borrowdate +
                "," + returndate+
                "," +fine
                ;
    }

    public String getReaderid() {
        return readerid;
    }

    public void setReaderid(String readerid) {
        this.readerid = readerid;
    }

    public String getISBN() {
        return ISBN;
    }

    public void setISBN(String ISBN) {
        this.ISBN = ISBN;
    }

    public String getBorrowdate() {
        return borrowdate;
    }

    public void setBorrowdate(String borrowdate) {
        this.borrowdate = borrowdate;
    }

    public String getReturndate() {
        return returndate;
    }

    public void setReturndate(String returndate) {
        this.returndate = returndate;
    }

    public double getFine() {
        return fine;
    }

    public void setFine(double fine) {
        this.fine = fine;
    }

}

借阅图书图书的增删改查及罚金设置方法
代码如下:

//罚金设置
    public void setFine1() {
        ArrayList<String> list = new ArrayList<>();
        try {
        FileReader f1 = new FileReader("readertype.txt");

        if ((f1.read())==-1){
            System.out.println("读者类型为空,请先添加!!!");
            return;
        }else {
            BufferedReader b1 = new BufferedReader(new FileReader("readertype.txt"));
            String s;
            while ((s=b1.readLine())!=null){
                list.add(s);
            }
        }
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要设置金额的读者类型编号:");
        String r=scanner.next();
        boolean flag=false;
        String[] chars = new String[6];
        for(String s:list){
            chars=s.split(",");
            if (chars[0].equals(r)){
                flag=true;
            }
        }
        if (!flag){
            System.out.println("输入的读者类型不存在!!!");
            return;
        }
        System.out.println("请输入你要设置的超过期限每日需缴纳的金额数:");
        double q = scanner.nextDouble();
        String[] chars1 = new String[6];
        ArrayList<ReaderType> findlist = new ArrayList<>();
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            String s1 = iterator.next();
            chars1 = s1.split(",");
            if (chars1[0].equals(r)) {
                ReaderType r1 = new ReaderType();
                r1.setTypeidr(r);
                r1.setTypenamer(chars1[1]);
                r1.setReaderid(chars1[2]);
                r1.setLimit(chars1[3]);
                r1.setMaxborrownum(chars1[4]);
                r1.setFine(q);
                findlist.add(r1);
                iterator.remove();
            }
        }
        //更新文件
        try {
            FileWriter fileWriter = new FileWriter("readertype.txt", false);
            StringBuffer stringBuffer = new StringBuffer();
            for (String s : list) {
                stringBuffer.append(s);
                stringBuffer.append("\n");
            }
            fileWriter.write(stringBuffer.toString());
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        for (int i=0;i<findlist.size();i++){
            try {
                    FileWriter f1 = new FileWriter("readertype.txt", true);
                    f1.write( findlist.get(i)+ "\n");
                    f1.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
        }
        System.out.println("罚金设置完成!!!");
    }

    //图书归还
    public static void backBook() {
        ArrayList<String>  borrowbook= new ArrayList<>();
        try {
        FileReader f1 = new FileReader("borrowbook.txt");
        int i=0;
        if ((i=f1.read())==-1){
            System.out.println("借阅信息为空,请先添加!!!");
            return;
        }else {
            BufferedReader b1 = new BufferedReader(new FileReader("borrowbook.txt"));
            String x;
            while ((x=b1.readLine())!=null){
                borrowbook.add(x);
            }
            b1.close();
        }
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你的读者编号:");
        String r=scanner.next();
        String[] chars = new String[5];
        boolean flag=false;
        for (String s:borrowbook){
            chars=s.split(",");
            if (chars[0].equals(r)){
                System.out.println("你借阅的图书为:" + chars[1]);
                flag=true;
            }
        }
        if (!flag){
            System.out.println("抱歉您没有借书!!!");
            return;
        }
        boolean flag1=false;
        System.out.println("请输入你要还的图书编号:");
        String b=scanner.next();
        String[] chars1 = new String[5];
        ArrayList<String> obj = new ArrayList<>();
        for (String a:borrowbook){
            chars1=a.split(",");
            if (chars1[0].equals(r)){
               obj.add(chars1[1]);
            }
        }
        for (int i=0;i<obj.size();i++){
            if (obj.get(i).equals(b)){
                flag1=true;
                break;
            }
        }
        if (!flag1){
            System.out.println("抱歉您没有借这本书!!!");
            return;
        }
        boolean flag2=false;
        Iterator<String> iterator = borrowbook.iterator();
        while (iterator.hasNext()){
            String s=iterator.next();
            chars=s.split(",");
            if (chars[0].equals(r) && chars[1].equals(b)) {
                ArrayList<String> readertype = new ArrayList<>();
                try {
                BufferedReader b1 = new BufferedReader(new FileReader("readertype.txt"));
                String a;
                while ((a=b1.readLine())!=null){
                    readertype.add(a);
                }
                    b1.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                double fine=0.0;
                String[] chars2 = new String[6];
                for (String a:readertype){
                    chars2=a.split(",");
                    if (chars2[2].equals(r)){
                        if (chars2[5].equals(0.0)){
                            System.out.println("请先添加罚款金额!!!");
                            return;
                        }else {
                            fine= Double.parseDouble(chars2[5]);
                            System.out.println(fine);
                            break;
                        }
                    }
                }
                LocalDateTime parse = LocalDateTime.parse(chars[3], formatter);
                if (parse.isBefore(localDateTime)) {
                    //计算相差天数
                    int x = (int) (localDateTime.toLocalDate().toEpochDay() - parse.toLocalDate().toEpochDay());
                    System.out.println("您以经拖欠了" + x + "天没有归还了,需缴纳" + x*fine + "元的罚金!!!");
                    flag2 = true;
                }
                iterator.remove();
            }
        }
        try {
            FileWriter fileWriter = new FileWriter("borrowbook.txt");
            StringBuffer stringBuffer = new StringBuffer();
            for (String s1:borrowbook){
                stringBuffer.append(s1);
                stringBuffer.append("\n");
            }
            fileWriter.write(stringBuffer.toString());
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (!flag2){
            System.out.println("您没有超时!!!");
        }
    }
    //借阅图书查看
    public static void searchBook() {
        try {
        FileReader f1 = new FileReader("borrowbook.txt");
        int i=0;
        char[] chars = new char[50];
        if ((i=f1.read(chars))==-1){
            System.out.println("借阅信息为空,请先添加!!!");
        }else {
            do {
                System.out.print(new String(chars, 0, i));
            }while ((i=f1.read(chars))!=-1);
        }
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //借阅图书
    public static void lendingBook() {
        ArrayList<String> booklist = new ArrayList<>();
        try {
        FileReader f1 = new FileReader("book.txt");
        int i=0;
        if ((i=f1.read())==-1){
            System.out.println("图书信息为空,请先添加!!!");
            return;
        }else {
            BufferedReader b1 = new BufferedReader(new FileReader("book.txt"));
            String x;
            while ((x=b1.readLine())!=null){
                booklist.add(x);
            }
            b1.close();
        }
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要借阅的图书编号:");
        String s=scanner.next();
        boolean flag=false;
        String[] chars = new String[9];
        for (String s1:booklist){
            chars=s1.split(",");
            if (chars[0].equals(s)){
                flag=true;
            }
        }
        if (!flag){
            System.out.println("输入的图书编号不存在!!!");
            return;
        }
        ArrayList<String>  readerlist= new ArrayList<>();
        try {
        BufferedReader b2 = new BufferedReader(new FileReader("reader.txt"));
        String x;
        while ((x=b2.readLine())!=null){
            readerlist.add(x);
        }
            b2.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("请输入你的读者编号:");
        String r=scanner.next();
        boolean flag1=false;
        String[] chars1 = new String[9];
        for ( String s1:readerlist) {
            chars1 = s1.split(",");
            if (chars1[0].equals(r)) {
                flag1=true;
            }
        }
        if (!flag1){
            System.out.println("你输入的读者信息不存在,请先添加!!!");
            return;
        }
        //判断读者是否还能借书
        ArrayList<String> readerType = new ArrayList<>();
        try {
        FileReader f1 = new FileReader("readertype.txt");
        if ((f1.read())==-1){
            System.out.println("读者类型为空请先添加!!!");
            return;
        } else {
            try {
                BufferedReader b1 = new BufferedReader(new FileReader("readertype.txt"));
                String s1;
                while ((s1 = b1.readLine()) != null) {
                    readerType.add(s1);
                }
                b1.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        boolean flag2=false;
        String[] chars3 = new String[6];
        for (String s1:readerType){
            chars3=s1.split(",");
            if (chars3[2].equals(r)){
                flag2=true;
                break;
            }
//            [4]
        }
        if (!flag2){
            System.out.println("抱歉你输入的读者没添加读者类型,请先添加!!!");
            return;
        }

        ArrayList<String>  borrowbook= new ArrayList<>();
        try {
            BufferedReader b2 = new BufferedReader(new FileReader("borrowbook.txt"));
            String x;
            while ((x=b2.readLine())!=null){
                borrowbook.add(x);
            }
            b2.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String[] chars2 = new String[6];
        for (String s1:borrowbook){
            chars2=s1.split(",");
            if (chars2[1].equals(s)){
                System.out.println("输入的图书已被人借走!!!");
                return;
            }
        }
        System.out.println("请输入你的要借阅的天数:(最高借阅不得超过17天,超过要扣钱!!)");
        int t=scanner.nextInt();
        if (t<0||t>17){
            System.out.println("请输入正确的日期!!!");
            return;
        }
        //提示信息
        System.out.println("恭喜你借阅成功");
        //创建借阅对象
        BorrowBook b = new BorrowBook();
        b.setReaderid(r);
        b.setISBN(s);
        b.setBorrowdate(time);
        b.setReturndate(formatter.format(localDateTime.plusDays(17)));
        try {
            FileWriter fileWriter = new FileWriter("borrowbook.txt",true);
            fileWriter.write(b+"\n");
            fileWriter.flush();
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

五、Reader.java

读者的基本信息
代码如下:

public class Reader {
    private String readerid;//读者编号
    private String readername;//读者姓名
    private String sex;//性别
    private String age;//年龄
    private String birthday;//出生日期
    private String phone;//电话
    private String dept;//所在院系
    private String regdate;//注册日期

    public Reader() {
    }

    public Reader(String readerid, String readername, String sex, String age, String birthday, String phone, String dept, String regdate) {
        this.readerid = readerid;
        this.readername = readername;
        this.sex = sex;
        this.age = age;
        this.birthday = birthday;
        this.phone = phone;
        this.dept = dept;
        this.regdate = regdate;
    }

    public String getReaderid() {
        return readerid;
    }

    public void setReaderid(String readerid) {
        this.readerid = readerid;
    }

    public String getReadername() {
        return readername;
    }

    public void setReadername(String readername) {
        this.readername = readername;
    }

    public String getSex() {
        return this.sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getAge() {
        return this.age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getPhone() {
        return this.phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getDept() {
        return dept;
    }

    public void setDept(String dept) {
        this.dept = dept;
    }

    public String getRegdate() {
        return this.regdate;
    }

    public void setRegdate(String regdate) {
        this.regdate = regdate;
    }

    @Override
    public String toString() {
        return  readerid +
                "," + readername +
                "," + birthday +
                "," + sex +
                ", "+ age +
                "," + phone +
                "," + regdate
                ;
    }

}

读者的增删改查方法
代码如下:

//删除读者信息
    public static void updateReader() {
        try {
            FileReader f2 = new FileReader("reader.txt");
            char[] chars = new char[50];
            if (( f2.read(chars))==-1){
                System.out.println("读者信息为空请先添加!!!");
                return;
            }
            f2.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        ArrayList<String>  reader = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要删除的读者编号:");
        String s = scanner.next();
        try {
        BufferedReader b1 = new BufferedReader(new FileReader("reader.txt"));
        String x;
        while ((x=b1.readLine())!=null){
            reader.add(x);
        }
            b1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        ArrayList<String> borrowBook = new ArrayList<>();
        try {
        BufferedReader b1 = new BufferedReader(new FileReader("borrowbook.txt"));
        String x;
        while ((x=b1.readLine())!=null){
            borrowBook.add(x);
        }
            b1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String[] chars1 = new String[5];
        for (String s1:borrowBook){
            chars1=s1.split(",");
            if (chars1[0].equals(s)){
                System.out.println("该读者借的书还未归还,不能删除!!!");
                return;
            }
        }
        boolean flag=false;
        String[] chars = new String[9];
        Iterator<String> iterator = reader.iterator();
        while (iterator.hasNext()){
            String s1=iterator.next();
            chars=s1.split(",");
            if (chars[0].equals(s)){
                iterator.remove();
                flag=true;
            }
        }
//        for (String r:reader){
//            chars=r.split(",");
//            if (chars[1].equals(s)){
//                reader.remove(new Integer(chars[1])-1);
//                flag=true;
//            }
//        }
        if (!flag){
            System.out.println("输入的编号不存在!!!");
            return;
        }
        try {
        FileWriter f1 = new FileWriter("reader.txt",false);
        StringBuffer stringBuffer = new StringBuffer();
        for (String r:reader){
            stringBuffer.append(r);
            stringBuffer.append("\n");
        }
        f1.write(stringBuffer.toString());
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        //给出删除成功提示
        System.out.println("删除读者信息成功!!!");
    }
    //查看读者信息
    public static void findAllReader() {
        try {
            FileReader b1 = new FileReader("reader.txt");
            int x;
            char[] chars = new char[50];
            if ((x=b1.read(chars))==-1){
                System.out.println("读者信息为空请先添加!!!");
                return;
            }else {
                do {
                    System.out.print(new  String(chars,0,x));
                }while ((x=b1.read(chars))!=-1);
            }
            b1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //增加读者信息
    public static void addReader() {
        ArrayList<String>  reader= new ArrayList<>();
        try {
        BufferedReader b1 = new BufferedReader(new FileReader("reader.txt"));
        String x;
        while ((x=b1.readLine())!=null){
            reader.add(x);
        }
            b1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入读者编号:");
        String readerid=scanner.next();
        String[] strings = new String[9];
        for (String r:reader){
            strings=r.split(",");
            if (strings[0].equals(readerid)){
                System.out.println("该读者已存在!!!");
                return;
            }
        }
        System.out.println("请输入读者姓名:");
        String readername = scanner.next();
        System.out.println("请输入读者出生日期:");
        String birthday = scanner.next();
        System.out.println("请输入读者性别:");
        String sex = scanner.next();
        ArrayList<String> o= new ArrayList<>();
        o.add("男");
        o.add("女");
        boolean flag=false;
        for (int i=0;i<o.size();i++){
            if (o.get(i).equals(sex)) {
                flag=true;
                break;
            }
        }
        if (!flag){
            System.out.println("请输入正确的操作!!!");
            return;
        }
        System.out.println("请输入读者年龄:");
        String age = scanner.next();
        System.out.println("请输入读者电话:");
        String phone = scanner.next();
        System.out.println("请输入读者注册日期:");
        String regdate = scanner.next();
        //创建读者对象
        Reader r = new Reader();
        r.setReaderid(readerid);
        r.setReadername(readername);
        r.setBirthday(birthday);
        r.setSex(sex);
        r.setAge(age);
        r.setPhone(phone);
        r.setRegdate(regdate);
        //提示信息
        System.out.println("添加读者信息成功!!!");
        try {
            FileWriter fileWriter = new FileWriter("reader.txt",true );
            fileWriter.write(String.valueOf(r) + "\n");
            fileWriter.flush();
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

六、ReaderType.java

读者类别的基本信息
代码如下:

public class ReaderType extends Reader{
    private String typeidr;//读者类别编号
    private String typenamer;//读者类别名称
    private String limit;//可借阅天数
    private String maxborrownum;//可借阅数量
    private double fine;//罚款金额

    public ReaderType() {
    }

    public ReaderType(String readerid, String readername, String sex, String age, String birthday, String phone, String dept, String regdate, String typeidr, String typenamer, String limit, String maxborrownum,double fine) {
        super(readerid, readername, sex, age, birthday, phone, dept, regdate);
        this.typeidr = typeidr;
        this.typenamer = typenamer;
        this.limit = limit;
        this.maxborrownum = maxborrownum;
        this.fine=fine;
    }

    public String getTypeidr() {
        return typeidr;
    }

    public void setTypeidr(String typeidr) {
        this.typeidr = typeidr;
    }

    public String getTypenamer() {
        return typenamer;
    }

    public void setTypenamer(String typenamer) {
        this.typenamer = typenamer;
    }

    public String getLimit() {
        return limit;
    }

    public void setLimit(String limit) {
        this.limit = limit;
    }

    public String getMaxborrownum() {
        return maxborrownum;
    }

    public void setMaxborrownum(String maxborrownum) {
        this.maxborrownum = maxborrownum;
    }

    public double getFine() {
        return fine;
    }

    public void setFine(double fine) {
        this.fine = fine;
    }

    @Override
    public String toString() {
        return  typeidr +
                "," + typenamer +
                "," + getReaderid() +
                "," + limit +
                "," + maxborrownum +
                ","+fine;
    }
}

读者类别的增删改查方法
代码如下:

//增加读者类别
    public static void selectReaderType() {
        ArrayList<String> readerTypes = new ArrayList<>();
        try {
        BufferedReader b1 = new BufferedReader(new FileReader("readertype.txt"));
        String x;
        while ((x=b1.readLine())!=null){
            readerTypes.add(x);
        }
            b1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要添加的读者类别编号:");
        String n=scanner.next();
        String[] chars = new String[3];
//        for (String s:readerTypes){
//            chars=s.split(",");
//            if (chars[0].equals(n)){
//                System.out.println("输入的读者类别编号已存在!!!");
//                return;
//            }
//        }
        System.out.println("请输入要添加的读者类别名称:");
        String m=scanner.next();
        boolean flag=true;
        for (String s:readerTypes){
            chars=s.split(",");
            if (chars[0].equals(n)&&chars[1].equals(m)){
                break;
            }
            if (chars[0].equals(n)){
                System.out.println("输入的读者类别编号已存在!!!");
                return;
            }
            if (chars[1].equals(m)) {
                flag=false;
                break;
            }
        }
        if (!flag){
            System.out.println("输入的读者类别名称已存在!!!");
            return;
        }
        ArrayList<String> reader = new ArrayList<>();
        try {
        FileReader f1 = new FileReader("reader.txt");
        int i=0;
        char[] chars1 = new char[9];
        if ((i=f1.read(chars1))==-1){
            System.out.println("对不起,你还没有添加读者,请先添加!!!");
            return;
        }else {
            BufferedReader b1 = new BufferedReader(new FileReader("reader.txt"));
            String x;
            while ((x=b1.readLine())!=null){
                reader.add(x);
            }
            b1.close();
        }
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        boolean flag1=false;
        System.out.println("请输入要添加的读者类别的读者编号:");
        String r=scanner.next();
        String[] chars1 = new String[9];
        for (String s:reader){
            chars1=s.split(",");
            if (chars1[0].equals(r)){
                flag1=true;
            }
        }
        if (!flag1){
            System.out.println("输入的读者编号不存在!!!");
            return;
        }
        for (String s:readerTypes){
            chars=s.split(",");
            if (chars[2].equals(r)){
                System.out.println("输入的读者已存在读者类型!!!");
                return;
            }
        }
        System.out.println("请输入要添加的读者类别的可借阅天数:");
        String t=scanner.next();
        String[] chars2 = new String[6];
        boolean flag2=true;
        for (String s:readerTypes){
            chars2=s.split(",");
            if (chars2[1].equals(m)&&chars2[3].equals(t)){
                break;
            }
            if (chars2[1].equals(m)){
                flag2=false;
                break;
            }
        }
        if (!flag2){
            System.out.println("请输入该类别的正确天数!!!");
            return;
        }
        System.out.println("请输入要添加的读者类别的可借阅数量:");
        String max=scanner.next();
        boolean flag3=true;
        for (String s:readerTypes){
            chars2=s.split(",");
            if (chars2[1].equals(m)&&chars2[4].equals(max)){
                break;
            }
            if (chars2[1].equals(m)){
                flag3=false;
                break;
            }
        }
        if (!flag3){
            System.out.println("请输入该类别的正确可借阅数量!!!");
            return;
        }
        //创建读者类型对象
        ReaderType ty = new ReaderType();
        ty.setTypeidr(n);
        ty.setTypenamer(m);
        ty.setReaderid(r);
        ty.setLimit(t);
        ty.setMaxborrownum(max);
        try {
            FileWriter f1 = new FileWriter("readertype.txt", true);
            f1.write(ty+ "\n");
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("添加读者类别成功!!!");
    }
    //删除读者类别
    public static void deleteReaderType() {
        ArrayList<String> readerTypes = new ArrayList<>();
        try {
        FileReader f1 = new FileReader("readertype.txt");
        char[] chars = new char[50];
        if ((f1.read(chars))==-1){
            System.out.println("读者类别为空,请先添加!!!");
            return;
        }else {
            BufferedReader b1 = new BufferedReader(new FileReader("readertype.txt"));
            String x;
            while ((x=b1.readLine())!=null){
                readerTypes.add(x);
            }
            b1.close();
        }
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要删除的读者类别编号:");
        String n=scanner.next();
        boolean flag=false;
        String[] chars = new String[5];
        Iterator<String> iterator = readerTypes.iterator();
        while (iterator.hasNext()){
            String s=iterator.next();
            chars=s.split(",");
            if (chars[0].equals(n)){
                iterator.remove();
                flag=true;
            }
        }
        if (!flag){
            System.out.println("输入的读者编号不存在!!!");
            return;
        }
        System.out.println("删除读者类别成功!!!");
        try {
        FileWriter f1 = new FileWriter("readertype.txt");
        StringBuffer stringBuffer = new StringBuffer();
        for (String s:readerTypes){
            stringBuffer.append(s);
            stringBuffer.append("\n");
        }
        f1.write(stringBuffer.toString());
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //修改读者类别
    public static void updateReaderType() {
        System.out.println("请删除这个类型,再添加一个新类型!!!");
    }
    //查询读者类别
    public static void insertReaderType() {
        try {
            FileReader f1 = new FileReader("readertype.txt");
            int i = 0;
            char[] chars = new char[3];
            if ((i = f1.read(chars)) == -1) {
                System.out.println("读者类型为空,请先添加!!!");
            }else {
                do {
                    System.out.print(new String(chars,0,i));//为什么一定要用do{}while()
                } while ((i = f1.read(chars)) != -1);
            }//用while(){}会丢失掉第一个编号
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

七、Users.java

用户及管理员的基本信息
代码如下:

public class Users extends Text{
    private static String usersid;//用户编号
    private String usersname;//用户名
    private String passwowrd;//密码

    public Users() {
    }

    @Override
    public String toString() {
        return  usersid +
                "," + usersname +
                "," + passwowrd  ;
    }

    public Users(String usersid, String usersname, String passwowrd) {
        this.usersid = usersid;
        this.usersname = usersname;
        this.passwowrd = passwowrd;
    }

    public String getUsersid() {
        return usersid;
    }

    public void setUsersid(String usersid) {
        this.usersid = usersid;
    }

    public String getUsersname() {
        return usersname;
    }

    public void setUsersname(String usersname) {
        this.usersname = usersname;
    }

    public String getPasswowrd() {
        return passwowrd;
    }

    public void setPasswowrd(String passwowrd) {
        this.passwowrd = passwowrd;
    }

    //管理员登陆
    public static void gly(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入管理员账号:");
        String zh=scanner.next();
        System.out.println("请输入管理员密码:");
        String mm=scanner.next();
        if (zh.equals("lhk")){
            if (mm.equals("123")){
                System.out.println("登陆成功!!!");
                try {
                    File file = new File("tempuser.txt");
                    FileWriter fileWriter = new FileWriter("tempuser.txt",false);
                    fileWriter.write(zh+"\n");
                    fileWriter.write(mm+"\n");
                    fileWriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }else {
                System.out.println("输入的密码错误!!!");
                gly();
            }
        }else {
            System.out.println("输入的管理员账号错误!!!");
            gly();
        }
    }
}

用户的增删改查方法
代码如下:

//登陆账号
    public static void landzh() {
        ArrayList<String> u = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名:");
        String zh=scanner.next();
        System.out.println("请输入用户密码:");
        String mm=scanner.next();
        try {
            BufferedReader b = new BufferedReader(new FileReader("users.txt"));
            String i=null;
            while ((i=b.readLine())!=null){
                u.add(i);
            }
            b.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String[] u1=new String[3];
        for (String user:u){
            u1=user.split(",");
            if (zh.equals(u1[1])&&mm.equals(u1[2])){
                System.out.println("登陆成功!!!");
                try {
                    File file = new File("tempuser.txt");
                    FileWriter fileWriter = new FileWriter("tempuser.txt",false);
                fileWriter.write(zh+"\n");
                fileWriter.write(mm+"\n");
                    fileWriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return;
            }
        }
        System.out.println("用户名不存在或密码错误,请重新输入!!!");
        landzh();
    }

    //注册账号
    public static void registerzh() {
        ArrayList<String> u= new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        try {
            BufferedReader szh = new BufferedReader(new FileReader("users.txt"));
            String x=null;
            while ((x=szh.readLine())!=null){
                u.add(x);
            }
            szh.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String[] u1=new String[3];
        System.out.println("请输入用户编号:");
        String i=scanner.next();
        for (String user:u){
            u1=user.split(",");
            if (i.equals(u1[0])){
                System.out.println("用户编号存在!");
                return;
            }
        }
        System.out.println("请输入用户名:");
        String zh=scanner.next();
        for (String user:u){
            u1=user.split(",");
            if (zh.equals(u1[1])){
                System.out.println("用户名存在!");
                return;
            }
        }
        System.out.println("请输入密码:");
        String mm0=scanner.next();
        System.out.println("请再次输入密码:");
        String mm1=scanner.next();

        if (mm0.equals(mm1)){
            System.out.println("恭喜你注册账号成功!");
        }else {
            System.out.println("两次密码不一致,请重新输入!");
            registerzh();
        }
        Users users = new Users();
        users.setUsersid(i);
        users.setUsersname(zh);
        users.setPasswowrd(mm0);
        try {
            FileWriter f1 = new FileWriter("users.txt",true);
            f1.write(users+"\n");
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //查询用户
    public static void insertUsers() {
        ArrayList<String> temp = new ArrayList<>();
        try {
            BufferedReader f1 = new BufferedReader(new FileReader("tempuser.txt"));
            String x;
            while ((x=f1.readLine())!=null){
                temp.add(x);
            }
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        boolean flag=false;
        if (temp.get(0).equals("lhk")){
            flag=true;
        }
        if (!flag){
            System.out.println("抱歉,你没有该权限!!!");
            return;
        }
        try {
        FileInputStream f1 = new FileInputStream("users.txt");
            int i = 0;
            byte[] bytes = new byte[1024];
            while ((i=f1.read(bytes)) != -1) {
                System.out.print(new String(bytes,0,i));
            }
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //修改用户密码
    public static void updateUsers() {
        ArrayList<String>   temp = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要修改的用户密码:");
        String mm=scanner.next();
        try {
        BufferedReader f1 = new BufferedReader(new FileReader("tempuser.txt"));
        String x;
        while ((x=f1.readLine())!=null){
          temp.add(x);
        }
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (temp.get(0).equals("lhk")){
            System.out.println("抱歉管理员密码不能修改!!!");
            return;
        }
        boolean flag=false;
        if (temp.get(1).equals(mm)){
            flag=true;
        }
        if (!flag){
            System.out.println("输入的密码错误!!!");
            return;
        }
        System.out.println("请输入你要修改的新密码:");
        String mm1=scanner.next();
        System.out.println("请确认你要修改的新密码:");
        String mm2=scanner.next();
        boolean flag1=false;
        if (mm1.equals(mm2)){
            flag1=true;
        }
        if (!flag1){
            System.out.println("两次输入的密码不一致!!!");
            return;
        }
        ArrayList<String>  users= new ArrayList<>();
        try {
        BufferedReader b1 = new BufferedReader(new FileReader("users.txt"));
        String x;
        while ((x=b1.readLine())!=null){
            users.add(x);
        }
            b1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String a=null;
        String[] chars = new String[4];
        for (String s:users){
            chars=s.split(",");
            if (chars[1].equals(temp.get(0))){
                a=chars[0];
            }
        }
        Iterator<String> iterator = users.iterator();
        while (iterator.hasNext()){
            String s=iterator.next();
            chars=s.split(",");
            if (chars[1].equals(temp.get(0))){
                iterator.remove();
            }
        }
        try {
        FileWriter f1 = new FileWriter("users.txt",false);
        StringBuffer stringBuffer = new StringBuffer();
        for (String s:users){
            stringBuffer.append(s);
            stringBuffer.append("\n");
        }
        f1.write(stringBuffer.toString());
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("修改密码成功!!!");
        Users u = new Users();
        u.setUsersid(a);
        u.setUsersname(temp.get(0));
        u.setPasswowrd(mm1);
        try {
        FileWriter f2 = new FileWriter("users.txt", true);
        f2.write(u+"\n");
            f2.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //删除用户
    public static void deleteUsers() {
        Scanner scanner = new Scanner(System.in);
        ArrayList<String> temp = new ArrayList<>();
        try {
            BufferedReader f1 = new BufferedReader(new FileReader("tempuser.txt"));
            String x;
            while ((x=f1.readLine())!=null){
                temp.add(x);
            }
            f1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        boolean flag=false;
        if (temp.get(0).equals("lhk")){
            flag=true;
        }
        if (!flag){
            System.out.println("抱歉,你没有该权限!!!");
            return;
        }
        System.out.println("请输入你要删除的用户编号:");
        String id=scanner.next();
        ArrayList<String> users = new ArrayList<>();
        try {
        BufferedReader b1 = new BufferedReader(new FileReader("users.txt"));
        String x;
        while ((x=b1.readLine())!=null){
            users.add(x);
        }
            b1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        boolean flag1=false;
        String[] chars = new String[5];
        for (String s:users){
            chars=s.split(",");
            if (chars[0].equals(id)){
                flag1=true;
            }
        }
        if (!flag1){
            System.out.println("输入的用户编号不存在!!!");
        }
        String[] chars1 = new String[5];
        Iterator<String> iterator = users.iterator();
        while (iterator.hasNext()){
            String s=iterator.next();
            chars1=s.split(",");
            if (chars1[0].equals(id)){
                iterator.remove();
            }
        }
        System.out.println("删除用户成功!!!");
        try {
        FileWriter fileWriter = new FileWriter("users.txt");
        StringBuffer stringBuffer = new StringBuffer();
        for (String s:users){
            stringBuffer.append(s);
            stringBuffer.append("\n");
        }
        fileWriter.write(stringBuffer.toString());
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

八、Test.java

测试类的基本实现信息
代码如下:

public class Test {
    public static void main(String[] args) {
        show();
    }

    private static void show3() {
        System.out.println("------欢迎来到图书管理系统------");
        UsersDao usersDao = new UsersDao();
        usersDao.registerzh();
        show();
    }

    private static void show() {
        System.out.println("------欢迎来到图书管理系统------");
        System.out.println("1 用户登陆");
        System.out.println("2 管理员登陆");
        System.out.println("3 注册账号");
        System.out.println("4 退出系统");
        System.out.println("请选择你要进行的操作:");
        Scanner scanner = new Scanner(System.in);
        String sc=scanner.next();
        HashSet<String> S = new HashSet<>();
        S.add("1");
        S.add("2");
        S.add("3");
        S.add("4");
        for (String a:S){
            if (a.equals(sc)){
                switch (sc){
                    case "1":
                        System.out.println("----------欢迎来到读者登陆界面----------");
                        show0();
                        break;
                    case "2":
                        System.out.println("----------欢迎来到管理员登陆界面----------");
                        Administrator();
                        break;
                    case "3":
                        show3();
                        break;
                    case "4":
                        System.out.println("谢谢使用!!!");
                        System.exit(0);//jvm退出
                }
                return;
            }
        }
        System.out.println("输入的操作不合法!!!");
        show();
    }
    //管理员登陆
    private static void Administrator() {
        Users users = new Users();
        users.gly();
        show1();
    }
    //用户登陆
    private static void show0() {
        UsersDao usersDao = new UsersDao();
        usersDao.landzh();
        show1();
    }

    private static void show1() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("----------欢迎来到主界面----------");
        System.out.println("1 读者信息管理");//dzxxgl
        System.out.println("2 图书信息管理");//tsxxgl
        System.out.println("3 图书借阅管理");//tsjygl
        System.out.println("4 基本信息维护");//jbxxwh
        System.out.println("5 用户信息管理");//yhxxgl
        System.out.println("6 返回上一步");//fhsyb
        System.out.println("请输入你要选择的操作:");
        String b=scanner.next();
        HashSet<String> S = new HashSet<>();
        S.add("1");
        S.add("2");
        S.add("3");
        S.add("4");
        S.add("5");
        S.add("6");
        for (String a:S){
            if (a.equals(b)){
                switch (b){
                    case "1":
                        dzxxgl();
                        break;
                    case "2":
                        tsxxgl();
                        break;
                    case "3":
                        tsjygl();
                        break;
                    case "4":
                        jbxxwh();
                        break;
                    case "5":
                        yhxxgl();
                        break;
                    case "6":
                        show();
                        break;
                }
                return;
            }
        }
        System.out.println("输入的操作不合法!!!");
        show1();
    }

    private static void yhxxgl() {
        System.out.println("----------欢迎来到用户信息管理界面----------");
        System.out.println("1 修改密码");//xgmm
        System.out.println("2 用户查询");//yhcx
        System.out.println("3 用户删除");//yhsc
        System.out.println("4 返回上一步");
        System.out.println("请输入你要选择的操作:");
        Scanner scanner = new Scanner(System.in);
        String c = scanner.next();
        HashSet<String> S = new HashSet<>();
        S.add("1");
        S.add("2");
        S.add("3");
        S.add("4");
        for (String a:S){
            if (a.equals(c)){
                switch (c){
                    case "1":
                        xgmm();
                        break;
                    case "2":
                        yhcx();
                        break;
                    case "3":
                        yhsc();
                        break;
                    case "4":
                        show1();
                        break;
                }
                return;
            }
        }
        System.out.println("输入的操作不合法!!!");
        yhxxgl();
    }
    //用户删除
    private static void yhsc() {
        UsersDao usersDao = new UsersDao();
        usersDao.deleteUsers();
        yhxxgl();
    }

    //用户查询
    private static void yhcx() {
        UsersDao usersDao = new UsersDao();
        usersDao.insertUsers();
        yhxxgl();
    }

    //修改密码
    private static void xgmm() {
        UsersDao usersDao = new UsersDao();
        usersDao.updateUsers();
        show();
    }

    private static void jbxxwh() {
        System.out.println("----------欢迎来到基本信息维护界面----------");
        System.out.println("1 图书类别设置");//tslbsz
        System.out.println("2 读者类别设置");//dzlbsz
        System.out.println("3 罚金设置");//fjsz
        System.out.println("4 返回上一步");
        System.out.println("请输入你要选择的操作:");
        Scanner scanner = new Scanner(System.in);
        String c = scanner.next();
        HashSet<String> S = new HashSet<>();
        S.add("1");
        S.add("2");
        S.add("3");
        S.add("4");
        for (String a:S){
            if (a.equals(c)){
                switch (c){
                    case "1":
                        tslbsz();
                        break;
                    case "2":
                        dzlbsz();
                        break;
                    case "3":
                        fjsz();
                        break;
                    case "4":
                        show1();
                        break;
                }
                return;
            }
        }
        System.out.println("输入的操作不合法!!!");
        jbxxwh();
    }
//罚金设置
    private static void fjsz() {
        BorrowBookDao borrowBookDao = new BorrowBookDao();
        borrowBookDao.setFine1();
        jbxxwh();
    }
//读者类别设置
    private static void dzlbsz() {
        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("请输入你要选择的操作:");
        Scanner scanner = new Scanner(System.in);
        String c = scanner.next();
        HashSet<String> S = new HashSet<>();
        S.add("1");
        S.add("2");
        S.add("3");
        S.add("4");
        S.add("5");
        for (String a:S){
            if (a.equals(c)){
                ReaderTypeDao rtd = new ReaderTypeDao();
                switch (c){
                    case "1":
                        rtd.selectReaderType();
                        dzlbsz();
                        break;
                    case "2":
                        rtd.deleteReaderType();
                        dzlbsz();
                        break;
                    case "3":
                        rtd.updateReaderType();
                        dzlbsz();
                        break;
                    case "4":
                        rtd.insertReaderType();
                        dzlbsz();
                        break;
                    case "5":
                        jbxxwh();
                        break;
                }
                return;
            }
        }
        System.out.println("输入的操作不合法!!!");
        dzlbsz();
    }
//图书类别设置
    private static void tslbsz() {
        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("请输入你要选择的操作:");
        Scanner scanner = new Scanner(System.in);
        String c = scanner.next();
        HashSet<String> S = new HashSet<>();
        S.add("1");
        S.add("2");
        S.add("3");
        S.add("4");
        S.add("5");
        for (String a : S) {
            if (a.equals(c)) {
                BookTypeDao btd = new BookTypeDao();
                switch (c) {
                    case "1":
                        btd.selectBookType();
                        tslbsz();
                        break;
                    case "2":
                        btd.deleteBookType();
                        tslbsz();
                        break;
                    case "3":
                        btd.updateBookType();
                        tslbsz();
                        break;
                    case "4":
                        btd.insertBookType();
                        tslbsz();
                        break;
                    case "5":
                        jbxxwh();
                        break;
                }
                return;
            }
        }
        System.out.println("输入的操作不合法!!!");
        tslbsz();
    }

    private static void tsjygl() {
        System.out.println("----------欢迎来到图书借阅管理界面----------");
        System.out.println("1 图书借阅");//tsjy
        System.out.println("2 图书归还");//tsgh
        System.out.println("3 图书查看");//tsck
        System.out.println("4 返回上一步");
        System.out.println("请输入你要选择的操作:");
        Scanner scanner = new Scanner(System.in);
        String c = scanner.next();
        HashSet<String> S = new HashSet<>();
        S.add("1");
        S.add("2");
        S.add("3");
        S.add("4");
        for (String a:S){
            if (a.equals(c)){
                switch (c){
                    case "1":
                        tsjy();
                        break;
                    case "2":
                        tsgh();
                        break;
                    case "3":
                        tsck();
                        break;
                    case "4":
                        show1();
                        break;
                }
                return;
            }
        }
        System.out.println("输入的操作不合法!!!");
        tsjygl();
    }
    //图书查看
    private static void tsck() {
        BorrowBookDao borrowBook = new BorrowBookDao();
        borrowBook.searchBook();
        tsjygl();
    }
    //图书归还
    private static void tsgh() {
        BorrowBookDao borrowBook = new BorrowBookDao();
        borrowBook.backBook();
        tsjygl();
    }
    //图书借阅
    private static void tsjy() {
        BorrowBookDao borrowBook = new BorrowBookDao();
        borrowBook.lendingBook();
        tsjygl();
    }

    //图书信息管理
    private static void tsxxgl() {
        System.out.println("----------欢迎来到图书信息界面----------");
        System.out.println("1 图书信息添加");//tsxxtj
        System.out.println("2 图书信息查询");//tsxxcx
        System.out.println("3 图书信息修改");//tsxxxg
        System.out.println("4 图书信息删除");//tsxxsc
        System.out.println("5 返回上一步");
        System.out.println("请输入你要选择的操作:");
        Scanner scanner = new Scanner(System.in);
        String c = scanner.next();
        HashSet<String> S = new HashSet<>();
        S.add("1");
        S.add("2");
        S.add("3");
        S.add("4");
        S.add("5");
        for (String a:S){
            if (a.equals(c)){
                switch (c){
                    case "1":
                        tsxxtj();
                        break;
                    case "2":
                        tsxxcx();
                        break;
                    case "3":
                        tsxxxg();
                        break;
                    case "4":
                        tsxxsc();
                        break;
                    case "5":
                        show1();
                        break;
                }
                return;
            }
        }
        System.out.println("输入的操作不合法!!!");
        tsxxgl();
    }

    private static void tsxxcx() {
        BookDao book = new BookDao();
        book.fandAllBook();
        System.out.println(" ");
        tsxxgl();
    }

    //图书信息删除
    private static void tsxxsc() {
        BookDao book = new BookDao();
        book.deleteBook();
        tsxxgl();
    }
//图书信息修改
    private static void tsxxxg() {
        BookDao book = new BookDao();
        book.updateReader();
        tsxxgl();
    }
//图书信息添加
    private static void tsxxtj() {
        BookDao book = new BookDao();
        book.addBook();
        tsxxgl();
    }

    private static void show2() {
        System.out.println("输入的用户名和密码不正确,请重新输入!!!");
        show0();
    }
    //读者信息管理
    private static void dzxxgl() {
        System.out.println("----------欢迎来到读者管理界面----------");
        System.out.println("1 读者信息添加");//dzxxtj
        System.out.println("2 读者信息查询");//dzxxcx
        System.out.println("3 读者信息删除");//dzxxsc
        System.out.println("4 返回上一步");
        System.out.println("请输入你要选择的操作:");
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        HashSet<String> S = new HashSet<>();
        S.add("1");
        S.add("2");
        S.add("3");
        S.add("4");
        for (String a:S){
            if (a.equals(s)){
                switch (s){
                    case "1":
                        dzxxtj();
                        break;
                    case "2":
                        dzxxcx();
                        break;
                    case "3":
                        dzxxsc();
                        break;
                    case "4":
                        show1();
                        break;
                }
                return;
            }
        }
        System.out.println("输入的操作不合法!!!");
        dzxxgl();
    }
    //读者信息查询
    private static void dzxxcx() {
        ReaderDao reader = new ReaderDao();
        reader.findAllReader();
        dzxxgl();
    }

    //读者信息添加
    private static void dzxxtj() {
        ReaderDao reader = new ReaderDao();
        reader.addReader();
        dzxxgl();
    }
//读者信息删除
    private static void dzxxsc() {
        ReaderDao reader = new ReaderDao();
        reader.updateReader();
        dzxxgl();
    }
}

测试类的运行结果

如下:

1.登陆界面

java 图书馆 java图书馆管理系统源代码_System_03


2.主界面

java 图书馆 java图书馆管理系统源代码_System_04

3.读者管理界面

java 图书馆 java图书馆管理系统源代码_java_05

4.图书信息管理界面

java 图书馆 java图书馆管理系统源代码_提示信息_06

5.图书借阅管理界面

java 图书馆 java图书馆管理系统源代码_java 图书馆_07

6.基本信息维护界面

java 图书馆 java图书馆管理系统源代码_java_08

7.用户信息管理界面

java 图书馆 java图书馆管理系统源代码_java 图书馆_09


九、总结

以上就是本次实战项目分享的内容,通过本次实战掌握了I/O流的基本用法,同时也加强了自己对学习过的知识进行融合,但还有很多不足之处,希望各位小伙伴们指正。