packageoperation;importbook.Book;importbook.BookList;importjava.util.Scanner;publicclassAddOperationimplementsIOperation{publicvoidwork(BookList bookList){System.out.println("新增图书!");Scanner scanner =newScanner(System.in);System.out.println("输入你要新增书籍的名字:");String name = scanner.nextLine();System.out.println("输入你要新增书籍的作者:");String author = scanner.nextLine();System.out.println("输入你要新增书籍的类型:");String type = scanner.nextLine();System.out.println("输入你要查找新增书籍的价格:");int price = scanner.nextInt();Book book =newBook(name,author,price,type);int currentSize = bookList.getUsedSize();
bookList.setBookList(currentSize,book);
bookList.setUsedSize(currentSize +1);//放入一本书System.out.println("新增成功");}}
4.借阅图书
packageoperation;importbook.Book;importbook.BookList;importjava.util.Scanner;publicclassBorrowOperationimplementsIOperation{publicvoidwork(BookList bookList){System.out.println("借阅图书!");Scanner scanner =newScanner(System.in);System.out.println("输入你要借阅的书籍:");String name = scanner.nextLine();int currentSize = bookList.getUsedSize();for(int i =0; i < currentSize; i++){Book book = bookList.getBook(i);if(book.getName().equals(name)){
book.setBorrowed(true);System.out.println("借阅成功,借阅书籍信息如下:");System.out.println(book);return;}}System.out.println("借阅失败,没有这本书籍!");}}
5.删除图书
packageoperation;importbook.Book;importbook.BookList;importjava.util.Scanner;publicclassDelOperationimplementsIOperation{publicvoidwork(BookList bookList){System.out.println("删除图书!");Scanner scanner =newScanner(System.in);System.out.println("输入你要删除书籍:");String name = scanner.nextLine();int currentSize = bookList.getUsedSize();int index =-1;for(int i =0; i < currentSize; i++){Book book = bookList.getBook(i);if(book.getName().equals(name)){
index = i;break;}}//如果index==-1,说明没有这本书if(index ==-1){System.out.println("没有你要删除的图书");return;}//从这里开始删除for(int i =0; i < currentSize-1; i++){Book book = bookList.getBook(i +1);
bookList.setBookList(i,book);}
bookList.setUsedSize(currentSize -1);}}
6.显示图书
packageoperation;importbook.Book;importbook.BookList;publicclassDisplayOperationimplementsIOperation{publicvoidwork(BookList bookList){System.out.println("显示图书!");int currentSize = bookList.getUsedSize();for(int i =0; i < currentSize; i++){Book book = bookList.getBook(i);System.out.println(book);}}}
packageoperation;importbook.Book;importbook.BookList;importjava.util.Scanner;publicclassFindOperationimplementsIOperation{publicvoidwork(BookList bookList){System.out.println("查找图书!");Scanner scanner =newScanner(System.in);System.out.println("输入你要查找的书籍:");String name = scanner.nextLine();int size = bookList.getUsedSize();for(int i =0; i < size; i++){Book book = bookList.getBook(i);if(book.getName().equals(name)){System.out.println("找到了这本书");System.out.println(book);return;}}System.out.println("没有这本书");}}
packageoperation;importbook.Book;importbook.BookList;importjava.util.Scanner;publicclassReturnOperationimplementsIOperation{publicvoidwork(BookList bookList){System.out.println("归还图书!");Scanner scanner =newScanner(System.in);System.out.println("输入你要归还的书籍:");String name = scanner.nextLine();int currentSize = bookList.getUsedSize();for(int i =0; i < currentSize; i++){Book book = bookList.getBook(i);if(book.getName().equals(name)){
book.setBorrowed(false);System.out.println("归还成功,归还书籍信息如下:");System.out.println(book);return;}}System.out.println("归还失败,没有这本书籍!");}}