Java:反序列化和搜索对象时出现数组列表序列化错误

我的项目是关于图书馆管理系统的。我必须将数据存储到类的对象中,然后将它们存储到 arraylist 中。 然后我正在序列化数据

我有这些功能:

  1. 添加书籍();- 反序列化数组列表 - 执行操作 - 序列化数组列表

  2. 删除书();- 反序列化数组列表 - 执行操作 - 序列化数组列表

  3. 修改Bok(); - 反序列化数组列表 - 执行操作 - 序列化数组列表

  4. 问题书(); - 反序列化数组列表 - 执行操作 - 序列化数组列表

  5. 返回书();- 反序列化数组列表 - 执行操作 - 序列化数组列表

我的 ArrayList: public static ArrayList bookData = new ArrayList();

我用来序列化的代码:

        FileOutputStream fos = null;

        ObjectOutputStream oos = null;


        try {

            fos = new FileOutputStream("Database.ser");

            oos = new ObjectOutputStream(fos);

            oos.flush();

            oos.writeObject(bookData);

            oos.close();

            fos.close();

        }catch(Exception e){

            System.out.println("Exception Caught: "+e);

        }

我用来反序列化的代码:


    FileInputStream fis = null;

    ObjectInputStream ois = null;

    //ArrayList<Books> bookData = null;


    try {

        fis = new FileInputStream("Database.ser");

        ois = new ObjectInputStream(fis);

        bookData = (ArrayList<Library>) ois.readObject();


    }catch(Exception e){

        System.out.println("Exception Caught: "+e);

    }

我收到了一个异常,因为 BufferedReader 需要是瞬态的,并且已修复。但是现在,我认为我的序列化不起作用。每次我创建一本书时,我都会将它的索引(对象编号)存储在一个文本文件中。我的搜索技术都不起作用:捕获了 ArrayIndexOutOfBounds 异常。我试图做数组列表的大小+1,但这也不起作用。


至尊宝的传说
浏览 176回答 1
1回答

呼唤远方

我从您的代码中确定了导致错误的 2 件事:BufferedReader 扫描是您库的一部分,因此您尝试对其进行序列化/反序列化,因此会收到错误消息。您似乎永远不会增加 bookid。话虽如此,你应该对你的图书馆建模如下:图书馆包含书籍。public class Book implements Serializable{&nbsp;&nbsp;&nbsp; &nbsp; private static final long serialVersionUID = 24913L;&nbsp;static int bookId=0;&nbsp; &nbsp; &nbsp; &nbsp; // Stores ID of Booksdouble bookPrice;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Stores Price of Bookint availableCopies;&nbsp; &nbsp; &nbsp; &nbsp; // Stores Nos. of available copiesString bookTitle;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Stores title of BooksString bookAuthor;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Stores author of BookString bookSubject;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Stores Subject of Book//StringBuffer studentName; // Stores Name of Student which issued/Returned Book.StringBuffer issuedTo[] = new StringBuffer[1000];//Stores all names of students which issued same book.//Constructorspublic Book(){&nbsp; &nbsp; generateBookId();}public Book(String bookTitle, String bookAuthor, String bookSubject, double bookPrice, int availableCopies){&nbsp; &nbsp; generateBookId();&nbsp; &nbsp; this.bookTitle=bookTitle;&nbsp; &nbsp; this.bookAuthor=bookAuthor;&nbsp; &nbsp; this.bookSubject=bookSubject;&nbsp; &nbsp; this.bookPrice=bookPrice;&nbsp; &nbsp; this.availableCopies=availableCopies;}//Functionspublic static int generateBookId(){&nbsp; &nbsp; bookId++;&nbsp; &nbsp; &nbsp; &nbsp;//Incrementing Book Id&nbsp; &nbsp; return bookId;&nbsp; // Returning the incremented book Id}public int getBookId() throws IOException{&nbsp; &nbsp; return bookId;}public double getBookPrice() throws IOException{&nbsp; &nbsp; return bookPrice;}public String getBookTitle() throws IOException{&nbsp; &nbsp; return bookTitle;}public String getBookAuthor() throws IOException{&nbsp; &nbsp; return bookAuthor;}public String getBookSubject() throws IOException{&nbsp; &nbsp; return bookSubject;}public int getAvailableCopies() throws IOException{&nbsp; &nbsp; return availableCopies;}/*public void setBookId() throws IOException{&nbsp; &nbsp; bookId = Integer.parseInt(scan.readLine());}*/public void setBookPrice(double bookPrice) throws IOException{&nbsp; &nbsp; this.bookPrice = bookPrice;}public void setBookTitle(String bookTitle) throws IOException{&nbsp; &nbsp; this.bookTitle = bookTitle;}public void setBookAuthor(String bookAuthor) throws IOException{&nbsp; &nbsp; this.bookAuthor = bookAuthor;}public void setBookSubject(String bookSubject) throws IOException{&nbsp; &nbsp; this.bookSubject = bookSubject;}public void setNoOfCopies(int availableCopies) throws IOException{&nbsp; &nbsp; this.availableCopies = availableCopies;}public void addBookCopies() throws IOException{&nbsp; &nbsp; availableCopies++;}public void removeBookCopies() throws IOException{&nbsp; &nbsp; availableCopies--;}}和图书馆如下:public class Library implements Serializable{&nbsp;&nbsp;&nbsp; &nbsp; private static final long serialVersionUID = 24913L; //used to verify sender and reciever&nbsp; &nbsp;&nbsp; &nbsp; public static ArrayList<Book> bookData = new ArrayList<Book>();public void addBook(Book book){&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; try{&nbsp; &nbsp; &nbsp; &nbsp; objCount++;&nbsp; &nbsp; &nbsp; &nbsp; bookData.add(book);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; FileOutputStream fos = null;&nbsp; &nbsp; &nbsp; &nbsp; ObjectOutputStream oos = null;&nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fos = new FileOutputStream("Database.ser");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos = new ObjectOutputStream(fos);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.flush();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.writeObject(bookData);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.close();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fos.close();&nbsp; &nbsp; &nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; }finally{&nbsp; &nbsp; &nbsp; &nbsp; try{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; File file = new File("Books_Index.txt");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileWriter fw = new FileWriter(file, true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int count=getObjCount();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fw.write("\nBook Index ["+count+"] Contains Book Named: ["+book.getBookTitle()+"]");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fw.close();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //saveData();&nbsp; &nbsp; &nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}public void deleteBook(int index ,String title){&nbsp; &nbsp; //fetchData();&nbsp; &nbsp; FileInputStream fis = null;&nbsp; &nbsp; ObjectInputStream ois = null;&nbsp; &nbsp; //ArrayList<Books> bookData = null;&nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; fis = new FileInputStream("Database.ser");&nbsp; &nbsp; &nbsp; &nbsp; ois = new ObjectInputStream(fis);&nbsp; &nbsp; &nbsp; &nbsp; bookData = (ArrayList<Book>) ois.readObject();&nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; }&nbsp; &nbsp; int status=0;&nbsp; &nbsp; try{&nbsp; &nbsp; &nbsp; &nbsp; for(int i=0;i<bookData.size();i++)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(title.equalsIgnoreCase(bookData.get(i).getBookTitle()))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bookData.set(bookData.indexOf(i),null);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //changing the value to null so that index of books would be maintained&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // ...to avoid left shift&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; status=1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; if(status == 1)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Book Not Found.");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; FileOutputStream fos = null;&nbsp; &nbsp; &nbsp; &nbsp; ObjectOutputStream oos = null;&nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fos = new FileOutputStream("Database.ser");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos = new ObjectOutputStream(fos);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.flush();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.writeObject(bookData);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.close();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fos.close();&nbsp; &nbsp; &nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; }finally{&nbsp; &nbsp; &nbsp; &nbsp; try{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; File file = new File("Books_Index.txt");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileWriter fw = new FileWriter(file, true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int count = getObjCount();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fw.write("\n Book Index ["+count+"] got deleted. Book Named: ["+title+"]");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fw.close();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Delete Operation Finished.");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //saveData();&nbsp; &nbsp; &nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}public void modifyBook(int index,String title,double price,int availableCopies){&nbsp; &nbsp; //fetchData();&nbsp; &nbsp; FileInputStream fis = null;&nbsp; &nbsp; ObjectInputStream ois = null;&nbsp; &nbsp; //ArrayList<Books> bookData = null;&nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; fis = new FileInputStream("Database.ser");&nbsp; &nbsp; &nbsp; &nbsp; ois = new ObjectInputStream(fis);&nbsp; &nbsp; &nbsp; &nbsp; bookData = (ArrayList<Book>) ois.readObject();&nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; }&nbsp; &nbsp; int status=0;&nbsp; &nbsp; try{&nbsp; &nbsp; &nbsp; &nbsp; for(int i=0;i<bookData.size();i++)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(title.equalsIgnoreCase(bookData.get(i).getBookTitle()))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bookData.get(index).setBookPrice(price);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bookData.get(index).setNoOfCopies(availableCopies);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; status=1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; if(status == 1)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Book Not Found.");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; FileOutputStream fos = null;&nbsp; &nbsp; &nbsp; &nbsp; ObjectOutputStream oos = null;&nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fos = new FileOutputStream("Database.ser");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos = new ObjectOutputStream(fos);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.flush();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.writeObject(bookData);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.close();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fos.close();&nbsp; &nbsp; &nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; }finally{&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Modify Operation Finished.");&nbsp; &nbsp; &nbsp; &nbsp; //saveData();&nbsp; &nbsp; }}public void searchBook(int index,String title){&nbsp; &nbsp; //fetchData();&nbsp; &nbsp; FileInputStream fis = null;&nbsp; &nbsp; ObjectInputStream ois = null;&nbsp; &nbsp; //ArrayList<Books> bookData = null;&nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; fis = new FileInputStream("Database.ser");&nbsp; &nbsp; &nbsp; &nbsp; ois = new ObjectInputStream(fis);&nbsp; &nbsp; &nbsp; &nbsp; bookData = (ArrayList<Book>) ois.readObject();&nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; }&nbsp; &nbsp; int status=0;&nbsp; &nbsp; try{&nbsp; &nbsp; &nbsp; &nbsp; for(int i=0;i<bookData.size();i++)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(title.equalsIgnoreCase(bookData.get(i).getBookTitle()))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(bookData.get(i).getBookId() == getObjCount())&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Book Found at ["+i+"]");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Displaying Book Data....");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Book Title&nbsp; &nbsp; : "+bookData.get(i).getBookTitle());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Book Author&nbsp; &nbsp;: "+bookData.get(i).getBookAuthor());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Book Subject&nbsp; : "+bookData.get(i).getBookSubject());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Book Price&nbsp; &nbsp; : "+bookData.get(i).getBookPrice());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("No. of Copies : "+bookData.get(i).getAvailableCopies());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Internal Error Caught.[1] Index Mismatch");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Library.main();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; status=1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; if(status == 1)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Book Not Found.");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; FileOutputStream fos = null;&nbsp; &nbsp; &nbsp; &nbsp; ObjectOutputStream oos = null;&nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fos = new FileOutputStream("Database.ser");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos = new ObjectOutputStream(fos);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.flush();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.writeObject(bookData);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.close();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fos.close();&nbsp; &nbsp; &nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; }finally{&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Search Operation Finished.");&nbsp; &nbsp; &nbsp; &nbsp; //saveData();&nbsp; &nbsp; }}public void issueBook(int index,String title,String studName){&nbsp; &nbsp; int status = 0;&nbsp; &nbsp; //fetchData();&nbsp; &nbsp; FileInputStream fis = null;&nbsp; &nbsp; ObjectInputStream ois = null;&nbsp; &nbsp; //ArrayList<Books> bookData = null;&nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; fis = new FileInputStream("Database.ser");&nbsp; &nbsp; &nbsp; &nbsp; ois = new ObjectInputStream(fis);&nbsp; &nbsp; &nbsp; &nbsp; bookData = (ArrayList<Book>) ois.readObject();&nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; }&nbsp; &nbsp; try{&nbsp; &nbsp; &nbsp; &nbsp; for(int i=0;i<bookData.size();i++)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(title.equalsIgnoreCase(bookData.get(i).getBookTitle()))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(bookData.get(i).getBookId() == getObjCount())&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LocalDateTime now = LocalDateTime.now();&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Format formatter = new SimpleDateFormat("yyyy-MM-dd");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //String currentDate = formatter.format(date);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //i++;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bookData.get(i).removeBookCopies();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //i++;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; File file = new File("issueLogs.txt");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileWriter fw = new FileWriter(file, true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fw.write("\n["+dtf.format(now)+"] : Book Title : "+bookData.get(i).getBookTitle()+" was Issued by Student Name"+studName);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fw.close();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Internal Error Caught.[1] Index Mismatch");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Library.main();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; status=1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(status == 1)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("353");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; FileOutputStream fos = null;&nbsp; &nbsp; &nbsp; &nbsp; ObjectOutputStream oos = null;&nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fos = new FileOutputStream("Database.ser");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos = new ObjectOutputStream(fos);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.flush();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.writeObject(bookData);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.close();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fos.close();&nbsp; &nbsp; &nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; }finally{&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Issue Operation Finished.");&nbsp; &nbsp; &nbsp; &nbsp; //saveData();&nbsp; &nbsp; }}public void returnBook(int index,String title,String studName){&nbsp; &nbsp; int status=0;&nbsp; &nbsp; //fetchData();&nbsp; &nbsp; FileInputStream fis = null;&nbsp; &nbsp; ObjectInputStream ois = null;&nbsp; &nbsp; //ArrayList<Books> bookData = null;&nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; fis = new FileInputStream("Database.ser");&nbsp; &nbsp; &nbsp; &nbsp; ois = new ObjectInputStream(fis);&nbsp; &nbsp; &nbsp; &nbsp; bookData = (ArrayList<Book>) ois.readObject();&nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; }&nbsp; &nbsp; try{&nbsp; &nbsp; &nbsp; &nbsp; for(int i=0;i<bookData.size();i++)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(title.equalsIgnoreCase(bookData.get(i).getBookTitle()))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(bookData.get(i).getBookId() == getObjCount())&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LocalDateTime now = LocalDateTime.now();&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Format formatter = new SimpleDateFormat("yyyy-MM-dd");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //String currentdate = formatter.format(date);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //i++;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bookData.get(i).addBookCopies();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //i++; //are yaar he ka kelela mi??&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; File file = new File("returnLogs.txt");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileWriter fw = new FileWriter(file, true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fw.write("\n["+dtf.format(now)+"] : Book Title : "+bookData.get(i).getBookTitle()+" was Returned by Student Name"+studName);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fw.close();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Internal Error Caught.[1] Index Mismatch");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Library.main();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; status=1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(status == 1)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Line no 402");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; FileOutputStream fos = null;&nbsp; &nbsp; &nbsp; &nbsp; ObjectOutputStream oos = null;&nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fos = new FileOutputStream("Database.ser");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos = new ObjectOutputStream(fos);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.flush();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.writeObject(bookData);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oos.close();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fos.close();&nbsp; &nbsp; &nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }catch(Exception e){&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Exception Caught: "+e);&nbsp; &nbsp; }finally{&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Return Operation Finished.");&nbsp; &nbsp; &nbsp; &nbsp; //saveData();&nbsp; &nbsp; }}///////////////////////////////////////////////////////////////////////////////////////////////////public static int objCount=0;public static int getObjCount(){&nbsp; &nbsp; return objCount;}}最后,您可以拥有执行所有代码的主运行程序类:public class CreateLibrary {&nbsp; &nbsp; static final String username = "";&nbsp; &nbsp; static final String password = "";&nbsp; &nbsp; public static void main(String args[]) throws Exception{&nbsp; &nbsp; BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));&nbsp; &nbsp; System.out.println("Enter User Name: ");&nbsp; &nbsp; String enterUser= scan.readLine();&nbsp; &nbsp; System.out.println("Enter Password: ");&nbsp; &nbsp; String enterPass =scan.readLine();&nbsp; &nbsp; if(enterUser.equals(username) && enterPass.equals(password))&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Login Successful...\n\n");&nbsp; &nbsp; &nbsp; &nbsp; Library library = new Library();&nbsp; &nbsp; &nbsp; &nbsp; int choice=0;&nbsp; &nbsp; &nbsp; &nbsp; while(choice!=7)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Select From Below Options: ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("1. Add Book\n2. Modify Book\n3. Delete Book\n4. Search Book\n5. Issue Book\n6. Return Book\n7. LogOut");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter Your Choice: ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; choice = Integer.parseInt(scan.readLine());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch(choice)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 1:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Book book = new Book();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("_________________Enter Book Details_________________");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(" Enter title of the Book&nbsp; &nbsp; : ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; book.setBookTitle(scan.readLine());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(" Enter the Name of Author&nbsp; &nbsp;: ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; book.setBookAuthor(scan.readLine());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(" Enter the Subject of Book&nbsp; : ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; book.setBookSubject(scan.readLine());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(" Enter the Price of Book&nbsp; &nbsp; : ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; book.setBookPrice(Integer.parseInt(scan.readLine()));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(" Enter Number of Copies&nbsp; &nbsp; &nbsp;:");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; book.setNoOfCopies(Integer.parseInt(scan.readLine()));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; library.addBook(book);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 2:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter Index of Book you want to Modify: ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int index=Integer.parseInt(scan.readLine());&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("_________________Modify Book_________________");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter Title of Book to Modify: ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String title = scan.readLine();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter New Price of Book: ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double price = Double.parseDouble(scan.readLine());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter New Available copies of Book");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int availableCopies = Integer.parseInt(scan.readLine());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; library.modifyBook(index,title,price,availableCopies);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 3:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter Index of Book you want to Delete: ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int index=Integer.parseInt(scan.readLine());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("_________________Delete Book_________________");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter Title of Book to delete: ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String title = scan.readLine();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; library.deleteBook(index,title);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 4:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter Index of Book you want to Search: ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int index=Integer.parseInt(scan.readLine());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("_________________Search Book_________________");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter Title of Book to Search: ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String title = scan.readLine();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; library.searchBook(index,title);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 5:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter Index of Book you want to Issue: ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int index=Integer.parseInt(scan.readLine());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("_________________Issue Book_________________");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter Title of Book&nbsp; :&nbsp; ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String title = scan.readLine();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter Name of Student:&nbsp; ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String studName = scan.readLine();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; library.issueBook(index,title,studName);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 6:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter Index of Book you want to Return: ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int index=Integer.parseInt(scan.readLine());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("_________________Return Book_________________");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter Title of Book&nbsp; :&nbsp; ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String title = scan.readLine();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Enter Name of Student:&nbsp; ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String studName = scan.readLine();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; library.returnBook(index,title,studName);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 7:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.exit(0);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; } //if bracket&nbsp; &nbsp; else&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; System.out.println("Invalid Login Credentials. It's not that easy to get in.");&nbsp; &nbsp; &nbsp; &nbsp; System.out.print("Quiting...");&nbsp; &nbsp; &nbsp; &nbsp; Thread.sleep(800);&nbsp; &nbsp; }}}希望有帮助。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java