import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Scanner;

public class BookRentalSystem {

private static final String BOOK_LIST_FILE = “booklist.txt”;
private static final String RENTAL_LOG_FILE = “rentallog.txt”;
private static final String DESIGN = “--------------------------------------”;
private static final String DESIGN2 = “---------------------------------------------------------------------”;
private static final double RENTAL_PRICE_PER_DAY = 0.5;

private static ArrayList<Book> bookList;
private static ArrayList<RentalLog> rentalLog;

public static void main(String[] args) {
loadBookList();
loadRentalLog();
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 = { “| |”, “| Menu: |”,
“| 1. List of all books |”, “| 2. Rent a book |”,
“| 3. Return a book |”, “| 4. Show rental log |”,
“| 5. Quit |”, “| Enter your choice (1-5): |” };
for (int i = 0; i < menu.length; i++) {
System.out.println(menu[i]);
}
System.out.println(DESIGN);

try {
int choice = pick.nextInt();
switch (choice) {
case 1:
listAllBooks();
break;
case 2:
rentBook(pick);
break;
case 3:
returnBook(pick);
break;
case 4:
showRentalLog();
break;
case 5:
System.out.println(“\nThank you for using the Book Rental System!”);
saveRentalLog();
return;
default:
System.out.println(“\nInvalid choice. Please enter a number between 1 and 5.”);
break;
}
} catch (Exception e) {
System.err.println(“Invalid Input”);
pick.next();
}
}
}

private static void loadBookList() {
bookList = new ArrayList<Book>();
try (BufferedReader br = new BufferedReader(new FileReader(BOOK_LIST_FILE))) {
String line;
while ((line = br.readLine()) != null) {
String[] tokens = line.split(“,”);
bookList.add(new Book(tokens[0], tokens[1], Integer.parseInt(tokens[2]), Boolean.parseBoolean(tokens[3])));
}
} catch (IOException e) {
System.err.println(“Error while reading book list file: " + e.getMessage());
}
}

private static void listAllBooks() {
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);
}
}

private static void loadRentalLog() {
rentalLog = new ArrayList<RentalLog>();
try (BufferedReader br = new BufferedReader(new FileReader(RENTAL_LOG_FILE))) {
String line;
while ((line = br.readLine()) != null) {
String[] tokens = line.split(“,”);
rentalLog.add(new RentalLog(tokens[0], tokens[1], LocalDateTime.parse(tokens[2]),
LocalDateTime.parse(tokens[3]), Double.parseDouble(tokens[4])));
}
} catch (IOException e) {
System.err.println(“Error while reading rental log file: " + e.getMessage());
}
}

private static void saveRentalLog() {
try (FileWriter fw = new FileWriter(RENTAL_LOG_FILE)) {
for (RentalLog rental : rentalLog) {
fw.write(rental.toString());
}
} catch (IOException e) {
System.err.println(“Error while writing rental log file: " + e.getMessage());
}
}

private static void showRentalLog() {
System.out.println(DESIGN2);
System.out.println(”| Rental Log:\t\t\t\t\t\t\t |”);
System.out.println(“|\t Customer Name\t\tTitle\t\tRental Date\t Return Date\t Payment |”);
for (RentalLog rental : rentalLog) {
System.out.print(“| " + rental + " |\n”);
System.out.println(DESIGN2);
}
}

private static void rentBook(Scanner pick) {
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()) {
System.out.print("Enter customer name: ");
String customerName = pick.next();
LocalDateTime rentalDate = LocalDateTime.now();
LocalDateTime returnDate = rentalDate.plusDays(7);
double payment = RENTAL_PRICE_PER_DAY * 7;
rentalLog.add(new RentalLog(customerName, title, rentalDate, returnDate, payment));
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);
}
}

private static void returnBook(Scanner pick) {
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()) {
RentalLog rental = null;
for (RentalLog r : rentalLog) {
if (r.getBookTitle().equals(title) && r.getReturnDate() == null) {
rental = r;
break;
}
}
if (rental != null) {
LocalDateTime returnDate = LocalDateTime.now();
rental.setReturnDate(returnDate);
double payment = rental.getPayment();
System.out.println(“You have returned the book " + title + “. Your payment is $” + payment);
} else {
System.out.println(“Error: Rental record not found.”);
}
book.returnBook();
} 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);
}
}

private static class RentalLog {
private String customerName;
private String bookTitle;
private LocalDateTime rentalDate;
private LocalDateTime returnDate;
private double payment;

public RentalLog(String customerName, String bookTitle, LocalDateTime rentalDate, LocalDateTime returnDate,
double payment) {
this.customerName = customerName;
this.bookTitle = bookTitle;
this.rentalDate = rentalDate;
this.returnDate = returnDate;
this.payment = payment;
}

public String getCustomerName() {
return customerName;
}

public void setCustomerName(String customerName) {
this.customerName = customerName;
}

public String getBookTitle() {
return bookTitle;
}

public void setBookTitle(String bookTitle) {
this.bookTitle = bookTitle;
}

public LocalDateTime getRentalDate() {
return rentalDate;
}

public void setRentalDate(LocalDateTime rentalDate) {
this.rentalDate = rentalDate;
}

public LocalDateTime getReturnDate() {
return returnDate;
}

public void setReturnDate(LocalDateTime returnDate) {
this.returnDate = returnDate;
}

public double getPayment() {
return payment;
}

public void setPayment(double payment) {
this.payment = payment;
}

@Override
public String toString() {
return String.format(”%-20s %-20s %-20s %-20s %-10s”, customerName, bookTitle, rentalDate, returnDate, show the full code of it Also remove the override and used scanner only