当前位置:   article > 正文

java基础图书管理系统_设计一个表示图书的类,包含书名,作者,和出版日期

设计一个表示图书的类,包含书名,作者,和出版日期

前言:

采用java基础 io及以前的内容

目标:

为图书管理人员编写一个图书管理系统,图书管理系统的设计主要是实现对图书的管理和相关操作,包括3个表:

图书信息表——存储图书的基本信息,包括书号、书名、作者、出版社、出版日期、存馆数量、定价等。

读者信息表——存储读者的基本信息,包括学号、姓名、学院、专业班级等。

图书借阅表——存储读者借书的相关信息,包括学号、姓名、书号、书名、借阅日期、应还日期、归还日期等。

前期准备:创建类、创建三个表(这里采用Vector)

一、图书信息表:

  1. //这是图书
  2. public class Books implements Serializable {
  3. private int booknum;
  4. private String bookname;
  5. private String writername;
  6. private String publisher;//出版社
  7. private String publishtime;//出版社日期
  8. private int number=0;//馆藏数量
  9. private int price=0;
  10. public void setNumber(int number) {
  11. this.number = number;
  12. }
  13. public void setBooknum(int booknum) {
  14. this.booknum = booknum;
  15. }
  16. public void setBookname(String bookname) {
  17. this.bookname = bookname;
  18. }
  19. public void setWritername(String writername) {
  20. this.writername = writername;
  21. }
  22. public int getBooknum() {
  23. return booknum;
  24. }
  25. public String getBookname() {
  26. return bookname;
  27. }
  28. public String getWritername() {
  29. return writername;
  30. }
  31. public String getPublisher() {
  32. return publisher;
  33. }
  34. public String getPublishtime() {
  35. return publishtime;
  36. }
  37. public int getNumber() {
  38. return number;
  39. }
  40. public int getPrice() {
  41. return price;
  42. }
  43. public Books(int booknum,String bookname, String writername, String publisher
  44. , String publishtime, int number, int price){
  45. this.bookname=bookname;
  46. this.number=number;
  47. this.price=price;
  48. this.publisher=publisher;
  49. this.publishtime=publishtime;
  50. this.writername=writername;
  51. this.booknum=booknum;
  52. }
  53. @Override
  54. public String toString() {
  55. return "Books{" +
  56. "booknum=" + booknum +
  57. ", bookname='" + bookname + '\'' +
  58. ", writername='" + writername + '\'' +
  59. ", publisher='" + publisher + '\'' +
  60. ", publishtime='" + publishtime + '\'' +
  61. ", number=" + number +
  62. ", price=" + price +
  63. '}';
  64. }
  65. boolean equalsTwo(Books book){
  66. if((this.bookname.equals(book.getBookname())&&this.publishtime.equals(book.getPublishtime())&&this.writername.equals(book.getWritername())
  67. &&this.publisher.equals(book.getPublisher())&&this.getBooknum()==book.getBooknum()&&this.price==book.price)||this.getBooknum()==book.getBooknum()
  68. ){
  69. return true;
  70. }
  71. return false;
  72. }
  73. }

二、读者信息表:

  1. public class readman implements Serializable {
  2. private long number;//学号
  3. private String name;//姓名
  4. private String college;//学院
  5. private String majorclass;//专业班级
  6. public readman(long number, String name, String college, String majorclass) {
  7. this.number = number;
  8. this.name = name;
  9. this.college = college;
  10. this.majorclass = majorclass;
  11. }
  12. public void setNumber(long number) {
  13. this.number = number;
  14. }
  15. public void setName(String name) {
  16. this.name = name;
  17. }
  18. public void setCollege(String college) {
  19. this.college = college;
  20. }
  21. public void setMajorclass(String majorclass) {
  22. this.majorclass = majorclass;
  23. }
  24. public long getNumber() {
  25. return number;
  26. }
  27. public String getName() {
  28. return name;
  29. }
  30. public String getCollege() {
  31. return college;
  32. }
  33. public String getMajorclass() {
  34. return majorclass;
  35. }
  36. @Override
  37. public String toString() {
  38. return "readman{" +
  39. "number=" + number +
  40. ", name='" + name + '\'' +
  41. ", college='" + college + '\'' +
  42. ", majorclass='" + majorclass + '\'' +
  43. '}';
  44. }
  45. public boolean equalsT(readman r){
  46. if((this.college.equals(r.college)&&this.majorclass.equals(r.majorclass)&&
  47. this.name.equals(r.name)&& this.number==r.number)||
  48. this.number==r.number
  49. ){
  50. return true;
  51. }
  52. return false;
  53. }
  54. }

三、图书借阅表

  1. //借阅
  2. public class BookBorrow implements Serializable {
  3. private String manname;//读者姓名
  4. private long mannumber;//读者学号
  5. private int booknumber;//书号
  6. private String bookname;//书名
  7. private String borrowtime;//借阅时间
  8. private String returntime;//归还时间
  9. public BookBorrow(String manname, long mannumber,
  10. int booknumber, String bookname,
  11. String borrowtime, String returntime) {
  12. this.manname = manname;
  13. this.mannumber = mannumber;
  14. this.booknumber = booknumber;
  15. this.bookname = bookname;
  16. this.borrowtime = borrowtime;
  17. this.returntime = returntime;
  18. }
  19. public boolean equalst(BookBorrow b){
  20. if(this.booknumber==b.booknumber&&this.mannumber==b.mannumber){
  21. return true;
  22. }
  23. return false;
  24. }
  25. @Override
  26. public String toString() {
  27. return "BookBorrow{" +
  28. "manname='" + manname + '\'' +
  29. ", mannumber=" + mannumber +
  30. ", booknumber=" + booknumber +
  31. ", bookname='" + bookname + '\'' +
  32. ", borrowtime='" + borrowtime + '\'' +
  33. ", returntime='" + returntime + '\'' +
  34. '}';
  35. }
  36. public String getManname() {
  37. return manname;
  38. }
  39. public long getMannumber() {
  40. return mannumber;
  41. }
  42. public int getBooknumber() {
  43. return booknumber;
  44. }
  45. public String getBookname() {
  46. return bookname;
  47. }
  48. public String getBorrowtime() {
  49. return borrowtime;
  50. }
  51. public String getReturntime() {
  52. return returntime;
  53. }
  54. public void setManname(String manname) {
  55. this.manname = manname;
  56. }
  57. public void setMannumber(long mannumber) {
  58. this.mannumber = mannumber;
  59. }
  60. public void setBooknumber(int booknumber) {
  61. this.booknumber = booknumber;
  62. }
  63. public void setBookname(String bookname) {
  64. this.bookname = bookname;
  65. }
  66. public void setBorrowtime(String borrowtime) {
  67. this.borrowtime = borrowtime;
  68. }
  69. public void setReturntime(String returntime) {
  70. this.returntime = returntime;
  71. }
  72. }

用菜单选择方式完成下列功能:

1.图书信息添加功能:包括书号、书名、作者、出版社、存馆数量、定价等。

2.图书信息查询:分别按书名,按作者名,按出版社等进行查询。

3.图书信息排序:按书号、书名等按升序进行排序。

4.图书信息的修改、删除:按书号或书名进行图书的修改和删除。

5.读者信息添加功能:包括学号、姓名、学院、专业班级等。

6.读者信息查询:分别按学号、姓名、专业班级等进行查询。

7.读者信息排序:按学号、学院等按升序进行排序。

8.读者信息的修改、删除:按学号+姓名进行读者信息的修改和删除。

9.图书借阅:输入学号+书号,如果该书图书信息表中的存馆数量大于0,则可以借出,借出相应数量后修改图书信息表中的存馆数量,在图书借阅表添加该同学的借阅。

10.图书归还:输入学号+书号,修改图书信息表中的存馆数量,在图书借阅表中记录该同学的归还时间。

11.图书借阅查询:分别按学号、书名、学院等进行查询。

12.图书全部展示

13.退出

菜单如下(先展示一下全部菜单):

  1. public void menu(){
  2. while(loop){
  3. System.out.println("===========图书管理系统============");
  4. System.out.println("========1.图书信息添加功能=========");
  5. System.out.println("========2.图书信息查询============");
  6. System.out.println("========3.图书信息排序============");
  7. System.out.println("========4.图书信息的修改==========");
  8. System.out.println("========5.读者信息添加功能=========");
  9. System.out.println("========6.读者信息查询============");
  10. System.out.println("========7.读者信息排序============");
  11. System.out.println("========8.读者信息的修改、删除=====");
  12. System.out.println("========9.图书借阅===============");
  13. System.out.println("========10.图书归还==============");
  14. System.out.println("========11.图书借阅查询===========");
  15. System.out.println("========12.图书全部展示===========");
  16. System.out.println("========13.退出===========");
  17. System.out.println("========请输入序号===========");
  18. int a=1;
  19. String ss="1";
  20. boolean qq=true;
  21. while(qq){ //这个循环控制是不是输入的数字
  22. ss=myScanner.next();
  23. if(panduan(ss)) {
  24. //panduan是一个我自己定义的函数下面会介绍,功能是判断字符串是不是纯数字
  25. a=Integer.parseInt(ss);
  26. qq=false;
  27. }else {
  28. System.out.println("重新输入!");
  29. a=0;
  30. }}
  31. if(a!=0){
  32. switch (a){
  33. case 1:
  34. add();
  35. break;
  36. case 2:
  37. if(books.size()!=0){//首先判断books的数量,如果没有书籍的话,不能进入
  38. outFile();//把books写入文件,后面会介绍
  39. look();
  40. }else
  41. System.out.println("图书馆现在没有书籍!");
  42. break;
  43. case 3:
  44. if(books.size()!=0){
  45. outFile();
  46. qsort();
  47. }else{
  48. System.out.println("图书馆现在没有书籍!");
  49. }
  50. break;
  51. case 4:
  52. if(books.size()!=0){
  53. outFile();
  54. modify();
  55. }else{
  56. System.out.println("图书馆现在没有书籍!");
  57. }
  58. break;
  59. case 5:
  60. addReadman();
  61. break;
  62. case 6:
  63. if(readmans.size()!=0){//首先判断readmans的数量,如果没有书籍的话,不能进入
  64. manoutFile();//把readmans写入文件,后面会介绍
  65. findman();
  66. }else{
  67. System.out.println("现在表中没有读者信息!");
  68. }
  69. break;
  70. case 7:
  71. if(readmans.size()!=0){
  72. manoutFile();
  73. mansort();
  74. }else{
  75. System.out.println("现在表中没有读者信息!");
  76. }
  77. break;
  78. case 8:
  79. if(readmans.size()!=0){
  80. manoutFile();
  81. manmodify();
  82. }else{
  83. System.out.println("现在表中没有读者信息!");
  84. }
  85. break;
  86. case 9:
  87. if((readmans.size()!=0&&books.size()!=0)||bookBorrows.size()!=0){
  88. outFile();
  89. manoutFile();
  90. bookborrow();
  91. }else{
  92. System.out.println("现在表中没有信息!");
  93. }
  94. break;
  95. case 10:
  96. //首先判断bookBorrows的数量,如果没有书籍的话,不能进入
  97. if(bookBorrows.size()!=0){
  98. outFile();//把bookBorrows写入文件,后面会介绍
  99. manoutFile();
  100. bookreturn();
  101. }else{
  102. System.out.println("现在表中没有信息!");
  103. }
  104. break;
  105. case 11:
  106. if(bookBorrows.size()!=0){
  107. fileborrows();
  108. for (BookBorrow b:bookBorrows){
  109. System.out.println(b);
  110. }
  111. }else{
  112. System.out.println("现在表中没有信息!");
  113. }
  114. break;
  115. case 12:
  116. if(books.size()!=0){
  117. outFile();
  118. ObjectInputStream obi=null;
  119. try {
  120. obi=new ObjectInputStream(newFileInputStream("d:\\books.txt"));
  121. Vector<Books> books20=(Vector<Books>)obi.readObject();
  122. for(int i=0;i<books20.size();i++){
  123. Books book9=books20.get(i);
  124. System.out.println(book9);
  125. }
  126. } catch (Exception e) {
  127. e.printStackTrace();
  128. }finally {
  129. try {
  130. obi.close();
  131. } catch (IOException e) {
  132. e.printStackTrace();
  133. }
  134. }
  135. }else {
  136. System.out.println("图书馆现在没有书籍");
  137. }
  138. break;
  139. case 13:
  140. loop=false;
  141. break;
  142. default:
  143. System.out.println("输入错误!");
  144. break;
  145. }
  146. //三国演义 罗贯中 清华 2001-1-3 10 19
  147. }else{
  148. System.out.println("输入错误!重新输入吧!");
  149. }
  150. }
  151. System.out.println("已退出图书管理系统!");
  152. }

因为我们需要输入数字所以必须进行判断来除错(自定义panduan函数):

  1. public boolean panduan(String ss){
  2. for(int i=0;i<ss.length();i++){
  3. if(!Character.isDigit(ss.charAt(i))){
  4. return false;
  5. }
  6. }
  7. return true;
  8. }

因为要用io流写入文件,所以封装成了3个方法 :

  1. //books的文件操作
  2. void outFile(){
  3. try {
  4. BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("d:\\books.txt",false));
  5. bufferedWriter.write("");
  6. bufferedWriter.write("");
  7. //以上是清空之前的操作,以便于我们重新输入
  8. } catch (Exception e) {
  9. e.printStackTrace();
  10. }
  11. ObjectOutputStream obo=null;
  12. try {
  13. obo=new ObjectOutputStream(new FileOutputStream("d:\\books.txt"));
  14. obo.writeObject(books);
  15. } catch (IOException e) {
  16. e.printStackTrace();
  17. }finally {
  18. try {
  19. obo.close();
  20. } catch (IOException e) {
  21. e.printStackTrace();
  22. }
  23. }
  24. }

 

  1. //readmans的文件操作
  2. void manoutFile(){
  3. try {
  4. BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("d:\\readmans.txt",false));
  5. bufferedWriter.write("");
  6. bufferedWriter.write("");
  7. //以上是清空之前的操作,以便于我们重新输入
  8. } catch (Exception e) {
  9. e.printStackTrace();
  10. }
  11. ObjectOutputStream obo=null;
  12. try {
  13. obo=new ObjectOutputStream(new FileOutputStream("d:\\readmans.txt"));
  14. obo.writeObject(readmans);
  15. } catch (IOException e) {
  16. e.printStackTrace();
  17. }finally {
  18. try {
  19. obo.close();
  20. } catch (IOException e) {
  21. e.printStackTrace();
  22. }
  23. }
  24. }
  1. //借阅的文件操作
  2. public void fileborrows(){
  3. try {
  4. BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("d:\\borrows.txt",false));
  5. bufferedWriter.write("");
  6. bufferedWriter.write("");
  7. //以上是清空之前的操作,以便于我们重新输入
  8. } catch (Exception e) {
  9. e.printStackTrace();
  10. }
  11. ObjectOutputStream obo=null;
  12. try {
  13. obo=new ObjectOutputStream(new FileOutputStream("d:\\borrows.txt"));
  14. obo.writeObject(bookBorrows);
  15. } catch (IOException e) {
  16. e.printStackTrace();
  17. }finally {
  18. try {
  19. obo.close();
  20. } catch (IOException e) {
  21. e.printStackTrace();
  22. }
  23. }
  24. }

 

----------------------------------------------------------------------------------------------

下面将分别介绍以上功能

1.图书信息添加功能:包括书号、书名、作者、出版社、存馆数量、定价等。

  1. public void add(){
  2. System.out.println("========请添加图书信息=========");
  3. System.out.println("例如:1205 三国演义 罗贯中 清华 2001-1-3 10 99");
  4. String bookname;
  5. String writername;
  6. String publisher;//出版社
  7. String publishtime;//出版社日期
  8. int number = 0;//馆藏数量
  9. int price = 0;
  10. int booknum=0;
  11. booknum=myScanner.nextInt();
  12. bookname=myScanner.next();
  13. writername=myScanner.next();
  14. publisher=myScanner.next();
  15. publishtime= myScanner.next();
  16. number=myScanner.nextInt();
  17. price=myScanner.nextInt();
  18. Books book=new Books(booknum,bookname,writername, publisher
  19. , publishtime, number,price);
  20. int r=0;
  21. if(books.size()!=0){
  22. for (int i=0;i<books.size();i++){
  23. Books book1=books.get(i);
  24. if(book1.equalsTwo(book)){
  25. r++;
  26. }
  27. }}
  28. if(r==0){
  29. books.add(book);
  30. System.out.println("图书添加成功!");
  31. }else{
  32. System.out.println("图书添加失败!");
  33. }
  34. }

2.图书信息查询:分别按书名,按作者名,按出版社等进行查询。

  1. public void look() {
  2. boolean lp=true;
  3. outFile();
  4. while (lp) {
  5. rr=true;
  6. System.out.println("1.根据书名查找");
  7. System.out.println("2.根据作者名查找");
  8. System.out.println("3.根据出版社查找");
  9. System.out.println("=====请输入序号=====");
  10. int a;
  11. char y = '1';
  12. y = myScanner.next().charAt(0);
  13. if(!Character.isDigit(y)){
  14. System.out.println("输入错误,请重新输入!");
  15. }
  16. if (Character.isDigit(y)) {
  17. String s = String.valueOf(y);
  18. a = Integer.parseInt(s);
  19. switch (a) {
  20. case 1:
  21. String name;
  22. System.out.println("请输入书名~");
  23. name = myScanner.next();
  24. if (books.size() == 0) {
  25. System.out.println("目前图书馆没有书籍~");
  26. return;
  27. }
  28. int u = 0;//
  29. //
  30. ObjectInputStream obi=null;
  31. try {
  32. obi=new ObjectInputStream(new FileInputStream("d:\\books.txt"));
  33. Vector<Books> book =(Vector<Books>)obi.readObject();
  34. for(Books books1:book){
  35. if(books1.getBookname().equals(name)){
  36. System.out.println(books1);
  37. u++;
  38. }
  39. }
  40. } catch (IOException | ClassNotFoundException e) {
  41. e.printStackTrace();
  42. }finally {
  43. try {
  44. obi.close();
  45. } catch (IOException e) {
  46. e.printStackTrace();
  47. }
  48. //}
  49. //u++;
  50. // }
  51. }
  52. if (u == 0) {
  53. System.out.println("没有该书籍");
  54. }
  55. while (rr) {
  56. System.out.println("是否继续查找?");
  57. System.out.println("1.继续");
  58. System.out.println("2.退出");
  59. int t;
  60. char w = '1';
  61. y = myScanner.next().charAt(0);
  62. if (Character.isDigit(y)) {
  63. String d = String.valueOf(y);
  64. t = Integer.parseInt(d);
  65. switch (t) {
  66. case 1:
  67. rr=false;
  68. break;
  69. case 2:
  70. lp = false;
  71. rr=false;
  72. break;
  73. default:
  74. System.out.println("输入错误!!!");
  75. break;
  76. }
  77. }
  78. }
  79. break;
  80. case 2:
  81. String name1;
  82. System.out.println("请输入作者名~");
  83. name = myScanner.next();
  84. if (books.size() == 0) {
  85. System.out.println("目前图书馆没有书籍~");
  86. return;
  87. }
  88. int u1 = 0;
  89. ObjectInputStream obi1=null;
  90. try {
  91. obi1=new ObjectInputStream(new FileInputStream("d:\\books.txt"));
  92. Vector<Books> book =(Vector<Books>)obi1.readObject();
  93. for(Books books1:book){
  94. if(books1.getWritername().equals(name)){
  95. System.out.println(books1);
  96. u1++;
  97. }
  98. }
  99. } catch (IOException | ClassNotFoundException e) {
  100. e.printStackTrace();
  101. }finally {
  102. try {
  103. obi1.close();
  104. } catch (IOException e) {
  105. e.printStackTrace();
  106. }
  107. //}
  108. //u++;
  109. // }
  110. }
  111. if (u1 == 0) {
  112. System.out.println("没有该书籍");
  113. }
  114. while (rr) {
  115. System.out.println("是否继续查找?");
  116. System.out.println("1.继续");
  117. System.out.println("2.退出");
  118. int t;
  119. char w = '1';
  120. w = myScanner.next().charAt(0);
  121. if (Character.isDigit(w)) {
  122. String d = String.valueOf(w);
  123. t = Integer.parseInt(d);
  124. switch (t) {
  125. case 1:
  126. rr=false;
  127. break;
  128. case 2:
  129. lp = false;
  130. rr=false;
  131. break;
  132. default:
  133. System.out.println("输入错误!!!");
  134. break;
  135. }
  136. }
  137. }
  138. break;
  139. case 3:
  140. String name11;
  141. System.out.println("请输入出版社名称~");
  142. name = myScanner.next();
  143. if (books.size() == 0) {
  144. System.out.println("目前图书馆没有书籍~");
  145. return;
  146. }
  147. int u11 = 0;
  148. ObjectOutputStream obo11=null;
  149. try {
  150. obo11=new ObjectOutputStream(new FileOutputStream("d:\\books.txt"));
  151. obo11.writeObject(books);
  152. } catch (IOException e) {
  153. e.printStackTrace();
  154. }finally {
  155. try {
  156. obo11.close();
  157. } catch (IOException e) {
  158. e.printStackTrace();
  159. }
  160. }
  161. ObjectInputStream obi11=null;
  162. try {
  163. obi11=new ObjectInputStream(new FileInputStream("d:\\books.txt"));
  164. Vector<Books> book =(Vector<Books>)obi11.readObject();
  165. for(Books books1:book){
  166. if(books1.getPublisher().equals(name)){
  167. System.out.println(books1);
  168. u11++;
  169. }
  170. }
  171. } catch (IOException | ClassNotFoundException e) {
  172. e.printStackTrace();
  173. }finally {
  174. try {
  175. obi11.close();
  176. } catch (IOException e) {
  177. e.printStackTrace();
  178. }
  179. }
  180. if (u11 == 0) {
  181. System.out.println("没有该书籍");
  182. }
  183. while (rr) {
  184. System.out.println("是否继续查找?");
  185. System.out.println("1.继续");
  186. System.out.println("2.退出");
  187. int t;
  188. char w1 = '1';
  189. w1 = myScanner.next().charAt(0);
  190. if (Character.isDigit(w1)) {
  191. String d = String.valueOf(w1);
  192. t = Integer.parseInt(d);
  193. switch (t) {
  194. case 1:
  195. rr=false;
  196. break;
  197. case 2:
  198. lp = false;
  199. rr=false;
  200. break;
  201. default:
  202. System.out.println("输入错误!!!");
  203. break;
  204. }
  205. }
  206. }
  207. break;
  208. default:
  209. System.out.println("输入错误!!!");
  210. }
  211. }
  212. }
  213. }

3.图书信息排序:按书号、书名等按升序进行排序。

  1. public void qsort(){
  2. //排序
  3. boolean lpp=true;
  4. while(lpp){
  5. boolean ee=true;
  6. System.out.println("请输入排序方法");
  7. System.out.println("1.按照书号");
  8. System.out.println("2.按照书名");
  9. int a;
  10. char y = '1';
  11. y = myScanner.next().charAt(0);
  12. if (Character.isDigit(y)) {
  13. String s = String.valueOf(y);
  14. a = Integer.parseInt(s);//重点,运用多次,判断输入是否为数字
  15. switch (a) {
  16. case 1:
  17. Collections.sort(books, new Comparator<Books>() {
  18. @Override
  19. public int compare(Books o1, Books o2) {
  20. return o1.getBooknum() - o2.getBooknum();
  21. }
  22. });
  23. for (Books book : books) {
  24. System.out.println(book);
  25. }
  26. while (ee) {
  27. System.out.println("是否继续排序?");
  28. System.out.println("1.继续");
  29. System.out.println("2.退出");
  30. int t;
  31. char w = '1';
  32. y = myScanner.next().charAt(0);
  33. if (Character.isDigit(y)) {
  34. String d = String.valueOf(y);
  35. t = Integer.parseInt(d);
  36. switch (t) {
  37. case 1:
  38. ee=false;
  39. break;
  40. case 2:
  41. lpp = false;
  42. ee=false;
  43. break;
  44. default:
  45. System.out.println("输入错误!!!");
  46. break;
  47. }
  48. }
  49. }
  50. break;
  51. case 2:
  52. Collections.sort(books, new Comparator<Books>() {
  53. @Override
  54. public int compare(Books o1, Books o2) {
  55. return o1.getBookname().compareTo(o2.getBookname());
  56. }
  57. });
  58. for (Books book : books) {
  59. System.out.println(book);
  60. }
  61. while (ee) {
  62. System.out.println("是否继续排序?");
  63. System.out.println("1.继续");
  64. System.out.println("2.退出");
  65. int t;
  66. char w = '1';
  67. y = myScanner.next().charAt(0);
  68. if (Character.isDigit(y)) {
  69. String d = String.valueOf(y);
  70. t = Integer.parseInt(d);
  71. switch (t) {
  72. case 1:
  73. ee=false;
  74. break;
  75. case 2:
  76. lpp = false;
  77. ee=false;
  78. break;
  79. default:
  80. System.out.println("输入错误!!!");
  81. break;
  82. }
  83. }
  84. }
  85. break;
  86. default:
  87. System.out.println("输入错误");
  88. break;
  89. }
  90. }
  91. }
  92. }

4.图书信息的修改、删除:按书号或书名进行图书的修改和删除。

  1. public void modify(){
  2. boolean op=true;
  3. boolean uu=true;
  4. while(op) {
  5. System.out.println("请输入按照书号or书名搜索修改");
  6. System.out.println("1.书号");
  7. System.out.println("2.书名");
  8. System.out.println("3.退出");
  9. String s= myScanner.next();
  10. Vector<Books> books1=new Vector<>();
  11. if(panduan(s)){
  12. int a=Integer.parseInt(s);
  13. switch (a){
  14. case 1:
  15. System.out.println("================");
  16. System.out.println("请输入书号~");
  17. String ss=myScanner.next();
  18. if(panduan(ss)){
  19. int a1=Integer.parseInt(ss);
  20. int y=0;
  21. ObjectInputStream obi=null;
  22. try {
  23. obi=new ObjectInputStream(new FileInputStream("d:\\books.txt"));
  24. Vector<Books> book11=(Vector<Books>)obi.readObject();
  25. for (int i=0;i<book11.size();i++){
  26. Books book=book11.get(i);
  27. if(book.getBooknum()==a1){
  28. books1.add(book);
  29. books.remove(i);
  30. y++;
  31. }
  32. }
  33. } catch (Exception e) {
  34. e.printStackTrace();
  35. }finally {
  36. try {
  37. obi.close();
  38. } catch (IOException e) {
  39. e.printStackTrace();
  40. }
  41. }
  42. if(y==0){
  43. System.out.println("没有找到该书籍!");
  44. }else{
  45. while(uu) {
  46. boolean ppp=true;
  47. System.out.println("请输入要修改的内容");
  48. System.out.println("1.书号");
  49. System.out.println("2.书名");
  50. System.out.println("3.作者名");
  51. System.out.println("4.删除该书籍");
  52. int t=1;
  53. char aa=myScanner.next().charAt(0);
  54. if(Character.isDigit(aa)){
  55. t=Integer.parseInt(String.valueOf(aa));
  56. switch (t){
  57. case 1:
  58. System.out.println("请输入书号:");
  59. int number=0;
  60. number=myScanner.nextInt();
  61. for(int i=0;i<books1.size();i++){
  62. Books bookss=books1.get(i);
  63. bookss.setBooknum(number);
  64. books.add(bookss);
  65. }
  66. System.out.println("修改成功~");
  67. while(ppp){
  68. System.out.println("是否继续修改?");
  69. System.out.println("1.是");
  70. System.out.println("2.否");
  71. int cc=2;
  72. char dc=myScanner.next().charAt(0);
  73. if(Character.isDigit(dc)){
  74. cc=Integer.parseInt(String.valueOf(dc));
  75. switch (cc){
  76. case 1:
  77. ppp=false ;
  78. break;
  79. case 2:
  80. ppp=false;
  81. uu=false;
  82. op=false;
  83. break;
  84. default:
  85. System.out.println("输入错误!");
  86. break;
  87. }
  88. }else{
  89. System.out.println("输入错误!");
  90. }
  91. }
  92. break;
  93. case 2:
  94. System.out.println("请输入书名:");
  95. String name1=myScanner.next();
  96. for(int i=0;i<books1.size();i++){
  97. Books book4=books1.get(i);
  98. book4.setBookname(name1);
  99. books.add(book4);
  100. }
  101. System.out.println("修改成功~");
  102. while(ppp){
  103. System.out.println("是否继续修改?");
  104. System.out.println("1.是");
  105. System.out.println("2.否");
  106. int cc=2;
  107. char dc=myScanner.next().charAt(0);
  108. if(Character.isDigit(dc)){
  109. cc=Integer.parseInt(String.valueOf(dc));
  110. switch (cc){
  111. case 1:
  112. ppp=false ;
  113. break;
  114. case 2:
  115. ppp=false;
  116. uu=false;
  117. op=false;
  118. break;
  119. default:
  120. System.out.println("输入错误!");
  121. break;
  122. }
  123. }else{
  124. System.out.println("输入错误!");
  125. }
  126. }
  127. break;
  128. case 3:
  129. System.out.println("请输入作者名:");
  130. String name2=myScanner.next();
  131. for(int i=0;i<books1.size();i++){
  132. Books book41=books1.get(i);
  133. book41.setWritername(name2);
  134. books.add(book41);
  135. }
  136. System.out.println("修改成功~");
  137. while(ppp){
  138. System.out.println("是否继续修改?");
  139. System.out.println("1.是");
  140. System.out.println("2.否");
  141. int cc=2;
  142. char dc=myScanner.next().charAt(0);
  143. if(Character.isDigit(dc)){
  144. cc=Integer.parseInt(String.valueOf(dc));
  145. switch (cc){
  146. case 1:
  147. ppp=false ;
  148. break;
  149. case 2:
  150. ppp=false;
  151. uu=false;
  152. op=false;
  153. break;
  154. default:
  155. System.out.println("输入错误!");
  156. break;
  157. }
  158. }else{
  159. System.out.println("输入错误!");
  160. }
  161. }
  162. break;
  163. case 4:
  164. break;
  165. default:
  166. System.out.println("输入错误!");
  167. break;
  168. }
  169. }else {
  170. System.out.println("输入错误!");
  171. }
  172. }
  173. }
  174. }
  175. break;
  176. case 2: System.out.println("================");
  177. System.out.println("请输入书名~");
  178. String sss=myScanner.next();
  179. int y=0;
  180. ObjectInputStream obi=null;
  181. try {
  182. obi=new ObjectInputStream(new FileInputStream("d:\\books.txt"));
  183. Vector<Books> book11=(Vector<Books>)obi.readObject();
  184. for (int i=0;i<book11.size();i++){
  185. Books book=book11.get(i);
  186. if(book.getBookname().equals(sss)){
  187. books1.add(book);
  188. books.remove(i);
  189. y++;
  190. }
  191. }
  192. } catch (Exception e) {
  193. e.printStackTrace();
  194. }finally {
  195. try {
  196. obi.close();
  197. } catch (IOException e) {
  198. e.printStackTrace();
  199. }
  200. }
  201. if(y==0){
  202. System.out.println("没有找到该书籍!");
  203. }else{
  204. while(uu) {
  205. boolean ppp=true;
  206. System.out.println("请输入要修改的内容");
  207. System.out.println("1.书号");
  208. System.out.println("2.书名");
  209. System.out.println("3.作者名");
  210. System.out.println("4.删除该书籍");
  211. int t=1;
  212. char aa=myScanner.next().charAt(0);
  213. if(Character.isDigit(aa)){
  214. t=Integer.parseInt(String.valueOf(aa));
  215. switch (t){
  216. case 1:
  217. System.out.println("请输入书号:");
  218. int number=0;
  219. number=myScanner.nextInt();
  220. for(int i=0;i<books1.size();i++){
  221. Books bookss=books1.get(i);
  222. bookss.setBooknum(number);
  223. books.add(bookss);
  224. }
  225. System.out.println("修改成功~");
  226. while(ppp){
  227. System.out.println("是否继续修改?");
  228. System.out.println("1.是");
  229. System.out.println("2.否");
  230. int cc=2;
  231. char dc=myScanner.next().charAt(0);
  232. if(Character.isDigit(dc)){
  233. cc=Integer.parseInt(String.valueOf(dc));
  234. switch (cc){
  235. case 1:
  236. ppp=false ;
  237. break;
  238. case 2:
  239. ppp=false;
  240. uu=false;
  241. op=false;
  242. break;
  243. default:
  244. System.out.println("输入错误!");
  245. break;
  246. }
  247. }else{
  248. System.out.println("输入错误!");
  249. }
  250. }
  251. break;
  252. case 2:
  253. System.out.println("请输入书名:");
  254. String name1=myScanner.next();
  255. for(int i=0;i<books1.size();i++){
  256. Books book4=books1.get(i);
  257. book4.setBookname(name1);
  258. books.add(book4);
  259. }
  260. System.out.println("修改成功~");
  261. while(ppp){
  262. System.out.println("是否继续修改?");
  263. System.out.println("1.是");
  264. System.out.println("2.否");
  265. int cc=2;
  266. char dc=myScanner.next().charAt(0);
  267. if(Character.isDigit(dc)){
  268. cc=Integer.parseInt(String.valueOf(dc));
  269. switch (cc){
  270. case 1:
  271. ppp=false ;
  272. break;
  273. case 2:
  274. ppp=false;
  275. uu=false;
  276. op=false;
  277. break;
  278. default:
  279. System.out.println("输入错误!");
  280. break;
  281. }
  282. }else{
  283. System.out.println("输入错误!");
  284. }
  285. }
  286. break;
  287. case 3:
  288. System.out.println("请输入作者名:");
  289. String name2=myScanner.next();
  290. for(int i=0;i<books1.size();i++){
  291. Books book41=books1.get(i);
  292. book41.setWritername(name2);
  293. books.add(book41);
  294. }
  295. System.out.println("修改成功~");
  296. while(ppp){
  297. System.out.println("是否继续修改?");
  298. System.out.println("1.是");
  299. System.out.println("2.否");
  300. int cc=2;
  301. char dc=myScanner.next().charAt(0);
  302. if(Character.isDigit(dc)){
  303. cc=Integer.parseInt(String.valueOf(dc));
  304. switch (cc){
  305. case 1:
  306. ppp=false ;
  307. break;
  308. case 2:
  309. ppp=false;
  310. uu=false;
  311. op=false;
  312. break;
  313. default:
  314. System.out.println("输入错误!");
  315. break;
  316. }
  317. }else{
  318. System.out.println("输入错误!");
  319. }
  320. }
  321. break;
  322. case 4:
  323. break;
  324. default:
  325. System.out.println("输入错误!");
  326. break;
  327. }
  328. }else {
  329. System.out.println("输入错误!");
  330. }
  331. }
  332. }
  333. break;
  334. case 3:
  335. uu=false;
  336. op=false;
  337. break;
  338. default:
  339. System.out.println("请重新输入!");
  340. break;
  341. }
  342. }else{
  343. System.out.println("输入错误,请重新输入!");
  344. }
  345. }//while的结束
  346. }

5.读者信息添加功能:包括学号、姓名、学院、专业班级等。

  1. public void addReadman(){
  2. System.out.println("=====请输入读者信息=====");
  3. System.out.println("例如:20102010 李华 山农 计算机类8班");
  4. long number=myScanner.nextLong();
  5. String name1 =myScanner.next();
  6. String college=myScanner.next();
  7. String majorclass=myScanner.next();
  8. readman man=new readman(number,name1,college,majorclass);
  9. int gg=0;
  10. if(readmans.size()!=0) {
  11. for(int i=0;i<readmans.size();i++) {
  12. readman rman=readmans.get(i);
  13. if(rman.equalsT(man)){
  14. gg++;
  15. }
  16. }
  17. }
  18. if(gg==0){
  19. readmans.add(man);
  20. System.out.println("添加读者信息成功~");
  21. }
  22. else System.out.println("读者添加失败!");
  23. }

6.读者信息查询:分别按学号、姓名、专业班级等进行查询。

  1. public void findman(){
  2. boolean ww=true;
  3. while(ww) {
  4. System.out.println("请输入查找读者信息方式");
  5. System.out.println("1.学号");
  6. System.out.println("2.姓名");
  7. System.out.println("3.专业班级");
  8. int w=1;
  9. char we=myScanner.next().charAt(0);
  10. if(Character.isDigit(we)){
  11. w=Integer.parseInt(String.valueOf(we));
  12. switch (w){
  13. case 1:
  14. System.out.println("请输入学号:");
  15. long num = myScanner.nextLong();
  16. int nn=0;
  17. ObjectInputStream obi = null;
  18. try {
  19. obi = new ObjectInputStream(new FileInputStream("d:\\readmans.txt"));
  20. Vector<readman> man = (Vector<readman>) obi.readObject();
  21. for (int i = 0; i < man.size(); i++) {
  22. readman man1 = man.get(i);
  23. if (man1.getNumber() == num) {
  24. System.out.println(man1);
  25. nn++;
  26. }
  27. }
  28. } catch (Exception e) {
  29. e.printStackTrace();
  30. } finally {
  31. try {
  32. obi.close();
  33. } catch (IOException e) {
  34. e.printStackTrace();
  35. }
  36. }
  37. if(nn==0){
  38. System.out.println("未找到该人!");
  39. }
  40. boolean rt=true;
  41. System.out.println("选择继续查询还是退出?");
  42. System.out.println("1.继续");
  43. System.out.println("2.退出");
  44. while(rt){
  45. int a=0;
  46. char ae=myScanner.next().charAt(0);
  47. if(Character.isDigit(ae)){
  48. a=Integer.parseInt(String.valueOf(ae));
  49. switch (a){
  50. case 1:
  51. rt=false;
  52. break;
  53. case 2:
  54. rt=false;
  55. ww=false;
  56. break;
  57. default:
  58. System.out.println("输入错误!");
  59. break;
  60. }
  61. }else{
  62. System.out.println("输入错误,请重新输入!");
  63. }
  64. }
  65. break;
  66. case 2:
  67. System.out.println("请输入姓名:");
  68. String s1 = myScanner.next();
  69. ObjectInputStream ob = null;
  70. int n1=00;
  71. try {
  72. ob = new ObjectInputStream(new FileInputStream("d:\\readmans.txt"));
  73. Vector<readman> man = (Vector<readman>) ob.readObject();
  74. for (int i = 0; i < man.size(); i++) {
  75. readman man1 = man.get(i);
  76. if (s1.equals(man1.getName())) {
  77. System.out.println(man1);
  78. n1++;
  79. }
  80. }
  81. } catch (Exception e) {
  82. e.printStackTrace();
  83. } finally {
  84. try {
  85. ob.close();
  86. } catch (IOException e) {
  87. e.printStackTrace();
  88. }
  89. }
  90. if(n1==0){
  91. System.out.println("未找到此人!");
  92. }
  93. boolean rtt=true;
  94. System.out.println("选择继续查询还是退出?");
  95. System.out.println("1.继续");
  96. System.out.println("2.退出");
  97. while(rtt){
  98. int a=0;
  99. char ae=myScanner.next().charAt(0);
  100. if(Character.isDigit(ae)){
  101. a=Integer.parseInt(String.valueOf(ae));
  102. switch (a){
  103. case 1:
  104. rtt=false;
  105. break;
  106. case 2:
  107. rtt=false;
  108. ww=false;
  109. break;
  110. default:
  111. System.out.println("输入错误!");
  112. break;
  113. }
  114. }else{
  115. System.out.println("输入错误,请重新输入!");
  116. }
  117. }
  118. break;
  119. case 3:
  120. System.out.println("请输入专业班级:");
  121. String s2 = myScanner.next();
  122. ObjectInputStream o = null;
  123. int n11=0;
  124. try {
  125. o = new ObjectInputStream(new FileInputStream("d:\\readmans.txt"));
  126. Vector<readman> man = (Vector<readman>) o.readObject();
  127. for (int i = 0; i < man.size(); i++) {
  128. readman man1 = man.get(i);
  129. if (s2.equals(man1.getMajorclass())) {
  130. System.out.println(man1);
  131. n11++;
  132. }
  133. }
  134. } catch (Exception e) {
  135. e.printStackTrace();
  136. } finally {
  137. try {
  138. o.close();
  139. } catch (IOException e) {
  140. e.printStackTrace();
  141. }
  142. }
  143. if(n11==0){
  144. System.out.println("未找到此人!");
  145. }
  146. boolean rttt=true;
  147. System.out.println("选择继续查询还是退出?");
  148. System.out.println("1.继续");
  149. System.out.println("2.退出");
  150. while(rttt){
  151. int a=0;
  152. char ae=myScanner.next().charAt(0);
  153. if(Character.isDigit(ae)){
  154. a=Integer.parseInt(String.valueOf(ae));
  155. switch (a){
  156. case 1:
  157. rttt=false;
  158. break;
  159. case 2:
  160. rttt=false;
  161. ww=false;
  162. break;
  163. default:
  164. System.out.println("输入错误!");
  165. break;
  166. }
  167. }else{
  168. System.out.println("输入错误,请重新输入!");
  169. }
  170. }
  171. break;
  172. default:
  173. System.out.println("输入错误,重新输入");
  174. break;
  175. }
  176. }else{
  177. System.out.println("输入错误,重新输入");
  178. }
  179. }
  180. }

7.读者信息排序:按学号、学院等按升序进行排序。

  1. public void mansort(){
  2. boolean ui=true;
  3. while(ui) {
  4. System.out.println("请输入排序方式");
  5. System.out.println("1.学号");
  6. System.out.println("2.学院");
  7. int aw=1;
  8. char bw=myScanner.next().charAt(0);
  9. if(Character.isDigit(bw)){
  10. aw=Integer.parseInt(String.valueOf(bw));
  11. switch (aw){
  12. case 1:
  13. Collections.sort(readmans, new Comparator<readman>() {
  14. @Override
  15. public int compare(readman o1, readman o2) {
  16. return (int)(o1.getNumber()- o2.getNumber());
  17. }
  18. });
  19. manoutFile();
  20. for(readman r:readmans){
  21. System.out.println(r);
  22. }
  23. boolean oo=true;
  24. while(oo){
  25. System.out.println("是否继续排序?");
  26. System.out.println("1.是");
  27. System.out.println("2.否");
  28. int q=1;
  29. char qx=myScanner.next().charAt(0);
  30. if(Character.isDigit(qx)){
  31. q=Integer.parseInt(String.valueOf(qx));
  32. switch (q){
  33. case 1:
  34. oo=false;
  35. break;
  36. case 2:
  37. oo=false;
  38. ui=false;
  39. break;
  40. default:
  41. System.out.println("输入错误!");
  42. break;
  43. }
  44. }else {
  45. System.out.println("输入错误!");
  46. }
  47. }
  48. break;
  49. case 2:
  50. Collections.sort(readmans, new Comparator<readman>() {
  51. @Override
  52. public int compare(readman o1, readman o2) {
  53. return o1.getMajorclass().compareTo(o2.getMajorclass());
  54. }
  55. });
  56. for(readman r1:readmans){
  57. System.out.println(r1);
  58. }
  59. manoutFile();
  60. boolean o=true;
  61. while(o){
  62. System.out.println("是否继续排序?");
  63. System.out.println("1.是");
  64. System.out.println("2.否");
  65. int q=1;
  66. char qx=myScanner.next().charAt(0);
  67. if(Character.isDigit(qx)){
  68. q=Integer.parseInt(String.valueOf(qx));
  69. switch (q){
  70. case 1:
  71. o=false;
  72. break;
  73. case 2:
  74. o=false;
  75. ui=false;
  76. break;
  77. default:
  78. System.out.println("输入错误!");
  79. break;
  80. }
  81. }else {
  82. System.out.println("输入错误!");
  83. }
  84. }
  85. break;
  86. default:
  87. System.out.println("输入错误!");
  88. break;
  89. }
  90. }else{
  91. System.out.println("输入错误!");
  92. }
  93. }
  94. }

8.读者信息的修改、删除:按学号+姓名进行读者信息的修改和删除。

  1. public void manmodify(){
  2. System.out.println("请输入读者的学号");
  3. long num=myScanner.nextLong();
  4. System.out.println("请输入读者的姓名");
  5. String name=myScanner.next();
  6. ObjectInputStream obi = null;
  7. Vector<readman> vc = null;
  8. Vector<readman> rt=new Vector<>();
  9. readman one=null;
  10. int y=0;
  11. try {
  12. obi = new ObjectInputStream(new FileInputStream("d:\\readmans.txt"));
  13. vc = (Vector<readman>) obi.readObject();
  14. } catch (Exception e) {
  15. e.printStackTrace();
  16. } finally {
  17. try {
  18. obi.close();
  19. } catch (IOException e) {
  20. e.printStackTrace();
  21. }
  22. }
  23. for(int i=0;i<vc.size();i++){
  24. readman er=vc.get(i);
  25. if(er.getNumber()==num&&name.equals(er.getName())){
  26. one=er;
  27. y++;
  28. readmans.remove(i);
  29. }
  30. }
  31. if(y==0){
  32. System.out.println("没有找到此人");
  33. }else {
  34. boolean uu = true;
  35. while (uu) {
  36. if(readmans.size()!=0){
  37. System.out.println("请输入要修改的内容");
  38. System.out.println("1.学号");
  39. System.out.println("2.姓名");
  40. System.out.println("3.学院");
  41. System.out.println("4.专业班级");
  42. System.out.println("5.删除此人");
  43. System.out.println("6.退出");
  44. int a = 1;
  45. char aa = myScanner.next().charAt(0);
  46. if (Character.isDigit(aa)) {
  47. a = Integer.parseInt(String.valueOf(aa));
  48. switch (a) {
  49. case 1:
  50. long num1;
  51. System.out.println("请输入修改的学号:");
  52. num1 = myScanner.nextLong();
  53. one.setNumber(num1);
  54. readmans.add(one);
  55. manoutFile();
  56. System.out.println("修改成功!");
  57. break;
  58. case 2:
  59. String name01 = null;
  60. System.out.println("请输入修改的名字:");
  61. name01 = myScanner.next();
  62. one.setName(name01);
  63. readmans.add(one);
  64. manoutFile();
  65. System.out.println("修改成功!");
  66. break;
  67. case 3:
  68. String name11 = null;
  69. System.out.println("请输入修改的学院:");
  70. name11 = myScanner.next();
  71. one.setCollege(name11);
  72. readmans.add(one);
  73. manoutFile();
  74. System.out.println("修改成功!");
  75. break;
  76. case 4:
  77. String name111 = null;
  78. System.out.println("请输入修改的专业班级:");
  79. name111 = myScanner.next();
  80. one.setMajorclass(name111);
  81. readmans.add(one);
  82. manoutFile();
  83. System.out.println("修改成功!");
  84. break;
  85. case 5:
  86. manoutFile();
  87. System.out.println("修改成功!");
  88. break;
  89. case 6:
  90. uu = false;
  91. break;
  92. default:
  93. System.out.println("输入错误!");
  94. break;
  95. }
  96. } else {
  97. System.out.println("输入错误!");
  98. }
  99. }else{
  100. uu=false;
  101. }
  102. }
  103. }
  104. }

9.图书借阅:输入学号+书号,如果该书图书信息表中的存馆数量大于0,则可以借出,借出相应数量后修改图书信息表中的存馆数量,在图书借阅表添加该同学的借阅。

  1. public void bookborrow(){
  2. System.out.println("请输入读者的学号");
  3. long num=myScanner.nextLong();
  4. System.out.println("请输入书籍的书号");
  5. int num1=myScanner.nextInt();
  6. ObjectInputStream obi =null;
  7. ObjectInputStream obo=null;
  8. Vector<Books> boo=null;
  9. Vector<readman> rea=null;
  10. Books b1=null;
  11. readman r1=null;
  12. try {
  13. obi=new ObjectInputStream(new FileInputStream("d:\\books.txt"));
  14. obo=new ObjectInputStream(new FileInputStream("d:\\readmans.txt"));
  15. boo=(Vector<Books>) obi.readObject();
  16. rea=(Vector<readman>)obo.readObject();
  17. } catch (Exception e) {
  18. e.printStackTrace();
  19. }finally {
  20. try {
  21. obi.close();
  22. } catch (IOException e) {
  23. e.printStackTrace();
  24. }
  25. }
  26. int y=0;
  27. int x=0;
  28. for (int i=0;i<rea.size();i++){
  29. readman r=rea.get(i);
  30. if(r.getNumber()==num){
  31. y++;
  32. r1=r;
  33. }
  34. }
  35. if(y!=0){
  36. for (int i=0;i<books.size();i++){
  37. Books b=books.get(i);
  38. if(b.getBooknum()==num1){
  39. x++;
  40. b1=b;
  41. }
  42. }
  43. if(b1!=null){
  44. if(b1.getNumber()>0){
  45. System.out.println("请输入你要借几本?");
  46. int aa;
  47. String y1 = null;
  48. y1 = myScanner.next();
  49. if (panduan(y1)) {
  50. aa = Integer.parseInt(y1);//重点,运用多次,判断输入是否为数字
  51. if(b1.getNumber()-aa>=0) {
  52. //System.out.println("222222");
  53. books.remove(b1);
  54. b1.setNumber(b1.getNumber() - aa);
  55. books.add(b1);
  56. LocalDateTime ldt = LocalDateTime.now();
  57. String time = ldt.getYear() + "年 " + ldt.getMonthValue() + "月 " + ldt.getDayOfMonth() + "日 " + ldt.getHour() + "时 " + ldt.getMinute() + "分 " + ldt.getSecond() + "秒\n";
  58. BookBorrow bookBorrow = new BookBorrow(r1.getName(), r1.getNumber(), b1.getBooknum()
  59. , b1.getBookname(), time, "无");
  60. bookBorrows.add(bookBorrow);
  61. fileborrows();
  62. outFile();
  63. System.out.println("借书成功!");
  64. }else{
  65. System.out.println("借书失败!"+" 该书目前有"+b1.getNumber()+"本");
  66. }
  67. }else{
  68. System.out.println("输入错误!");
  69. }
  70. }
  71. else{
  72. System.out.println("书籍已被借完!");
  73. }}else{
  74. System.out.println("未找到此人或此书籍!");
  75. }
  76. }else{
  77. System.out.println("未找到此人或此书籍!");
  78. }
  79. }

10.图书归还:输入学号+书号,修改图书信息表中的存馆数量,在图书借阅表中记录该同学的归还时间。

  1. public void bookreturn (){
  2. System.out.println("请输入归还者的学号");
  3. long num=myScanner.nextLong();
  4. System.out.println("请输入归还书籍的书号");
  5. int num1=myScanner.nextInt();
  6. BookBorrow bb = null;
  7. for (int i = 0; i < bookBorrows.size(); i++) {
  8. BookBorrow b = bookBorrows.get(i);
  9. if ((b.getMannumber()==num) && (b.getBooknumber()==num1)) {
  10. bb = b;
  11. bookBorrows.remove(b);
  12. }
  13. }
  14. if (bb != null) {
  15. LocalDateTime ldt1 = LocalDateTime.now();
  16. String time1 = ldt1.getYear() + "年 " + ldt1.getMonthValue() + "月 " + ldt1.getDayOfMonth() + "日 " + ldt1.getHour() + "时 " + ldt1.getMinute() + "分 " + ldt1.getSecond() + "秒\n";
  17. bb.setReturntime(time1);
  18. bookBorrows.add(bb);
  19. fileborrows();
  20. System.out.println("已全部归还!");
  21. } else {
  22. System.out.println("未借该书籍,不用还书");
  23. }
  24. }

11.图书借阅查询:分别按学号、书名、学院等进行查询。

 

  1. //图书借阅查询,直接放在了menu case11里面了
  2. if(bookBorrows.size()!=0){
  3. fileborrows();
  4. for (BookBorrow b:bookBorrows){
  5. System.out.println(b);
  6. }
  7. }else{
  8. System.out.println("现在表中没有信息!");
  9. }

 12.图书全部展示

//  因为代码并不长,也是直接放了 menu的case12里面了

  1. if(books.size()!=0){
  2. outFile();
  3. ObjectInputStream obi=null;
  4. try {
  5. obi=new ObjectInputStream(new FileInputStream("d:\\books.txt"));
  6. Vector<Books> books20=(Vector<Books>)obi.readObject();
  7. for(int i=0;i<books20.size();i++){
  8. Books book9=books20.get(i);
  9. System.out.println(book9);
  10. }
  11. } catch (Exception e) {
  12. e.printStackTrace();
  13. }finally {
  14. try {
  15. obi.close();
  16. } catch (IOException e) {
  17. e.printStackTrace();
  18. }
  19. }
  20. }else {
  21. System.out.println("图书馆现在没有书籍");
  22. }

 13.退出功能 : 就是让while里的loop变量变成false,并且在外面加一句提醒

System.out.println("已退出图书管理系统!");

 

总结:

这是java基础的一个小项目,能够体现基础知识的把握,做这个之前并没有学Mysql,所以就用到了io流。还在继续加油中~

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/556009
推荐阅读
相关标签
  

闽ICP备14008679号