java实战

您所在的位置:网站首页 java图书管理系统io流 java实战

java实战

2024-07-16 18:57:22| 来源: 网络整理| 查看: 265

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

前言

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

【项目内容】 项目功能结构图: 在这里插入图片描述

一、工程文件 文件目录:

在这里插入图片描述

二、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 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 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 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 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 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 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 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(


【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭