mport java.util.ArrayList;
import java.util.Scanner;

public class BookRentalSystem {
  
  public static void main(String[] args) {
    
    String design = "--------------------------------------";
    String design2 = "---------------------------------------------------------------------";
    
    ArrayList<Book> bookList = new ArrayList<Book>();
    bookList.add(new Book("Chitra", "R.N.Tagore\t\t ", 1990, true));
    bookList.add(new Book("Utopia", "Sir Thomas Moor           ", 1960, true));
    bookList.add(new Book("1984", "\t\tGeorge Orwell\t", 1949, true));
    bookList.add(new Book("Baburnama", "Babur\t\t\t ", 1813, true));
    bookList.add(new Book("Arthashatra", "Kautilya\t\t  ", 1951, true));

    Scanner pick = new Scanner(System.in);
    
    System.out.println(design);
    System.out.println("| Welcome to the Book Rental System! |");

    while (true) {
      System.out.println(design);
      //ARRAY AREA
      String [] menu = {"|\t\t\t\t     |\n| Menu:\t\t\t\t     |",
                                     "| 1. List of all books\t\t     |", 
                                     "| 2. Rent a book\t\t     |", 
                                     "| 3. Return a book\t\t     |", 
                                     "| 4. Quit\t\t\t     |"};  
      for (int i = 0; i < menu.length; i++){
          System.out.println(menu[i]);
      }
      System.out.println(design);
 
    try{
      System.out.print("\nEnter your choice (1-4): ");
      int choice = pick.nextInt();

      if (choice == 1) {
        System.out.println(design2);
            System.out.println("| Book List:\t\t\t\t\t\t\t    |");
                System.out.println("|\t  Title\t\t\tAuthor\t\t     Year Available |");
        for (Book book : bookList) {
          System.out.print("| " + book + " |\n");
          System.out.println(design2);
        }
        
      } else if (choice == 2) {
        System.out.print("\nEnter the title of the book you want to rent: ");
            String title = pick.next();
                boolean found = false;
        for (Book book : bookList) {
          
          if (book.getTitle().equalsIgnoreCase(title)) {
            
            if (book.isAvailable()) {
              book.rentBook();
                  System.out.println("You have rented the book " + title); 
            } else {
              System.out.println("Sorry, the book " + title + " is not available. Please choose another book.");
            }
            found = true;
            break;
          }
        }
        
        if (!found) {
          System.out.println("Sorry, we do not have the book " + title);
        }
        
      } else if (choice == 3) {
        System.out.print("\nEnter the title of the book you want to return: ");
            String title = pick.next();
                boolean found = false;
                
        for (Book book : bookList) {
          if (book.getTitle().equalsIgnoreCase(title)) {
            if (!book.isAvailable()) {
              book.returnBook();
              System.out.println("You have returned the book " + title);
            } else {
              System.out.println("You cannot return a book that has not been rented");
            }
            found = true;
            break;
          }
        }
        
        if (!found) {
          System.out.println("Sorry, we do not have the book " + title);
        } 
      } else if (choice == 4) {
        System.out.println("\nThank you for using the Book Rental System!");
        break;
      } else {
        System.out.println("\nInvalid choice. Please enter a number between 1 and 4.");   
       }//else if
      
     }catch(Exception e){
          System.err.println("Invlaid Input");
              pick.next();
          }
   }
  }
}

class Book {
  private String title;
  private String author;
  private int year;
  private boolean available;

  public Book(String title, String author, int year, boolean available) {
    this.title = title;
    this.author = author;
    this.year = year;
    this.available = available;
    }

public String getTitle() {
return title;
}

public String getAuthor() {
return author;
}

public int getYear() {
return year;
}

public boolean isAvailable() {
return available;
}

public void rentBook() {
available = false;
}

public void returnBook() {
available = true;
}

public String toString() {
String availability = available ? "Yes" : "No";
return title + "\t\t" + author + "\t" + year + "\t" + availability;
    }
} add the receipt and add the type writer and reader also add the date and time also add more books