Conversation with Merlin [email protected] · Thu Nov 23 2023

write a java code that determine book loan due date from library by using current time and borrowing period equal 5 days with method loan period is over.

Certainly! Below is a simple Java code that determines the book loan due date from a library based on the current time and a borrowing period of 5 days, and it includes a method to check if the loan period is over:

import java.time.LocalDate; public class LibraryBook { public static void main(String[] args) { // Get current date LocalDate currentDate = LocalDate.now(); // Borrowing period is 5 days int borrowingPeriod = 5; // Determine the due date for the book loan LocalDate dueDate = currentDate.plusDays(borrowingPeriod); System.out.println("Book loan due date: " + dueDate); // Check if the loan period is over if (isLoanPeriodOver(dueDate)) { System.out.println("The loan period is over."); } else { System.out.println("The loan period is not over."); } } // Method to check if the loan period is over public static boolean isLoanPeriodOver(LocalDate dueDate) { LocalDate currentDate = LocalDate.now(); return currentDate.isAfter(dueDate); } }

In this code, we use the java.time.LocalDate class to work with dates. The main method calculates the due date by adding the borrowing period to the current date. Then, it uses the isLoanPeriodOver method to check if the loan period is over by comparing the current date with the due date.

You can run this code to see the loan due date and whether the loan period is over based on the current date.