Question: I am working on making a Book class in Java. My java class is modeled after a POJO. This method rent(String renter) - has one

I am working on making a Book class in Java. My java class is modeled after a POJO. This method rent(String renter) - has one String type parameter and no return type. It rents the book out to the specified renter and sets the due date to be a week from the current date. You can see in my code that I have a method called public void rent(String renter). My question is, how can I assign the renter to a book, and how can I set the due date as well?

Here is my code:

import java.time.LocalDate; public class Book { private String name; private String author; private String renter; private boolean rentstatus; private LocalDate dueDate; public Book(String name, String author) { this.name = name; this.author = author; renter = null; rentstatus = false; } public Book(String name, String author, String renter) { this.name = name; this.author = author; this.renter = renter; rentstatus = true; } public Book(String name, String author, String renter, LocalDate dueDate) { this.name = name; this.author = author; this.renter = renter; this.dueDate = dueDate; rentstatus = true; } public boolean isRented() { return rentstatus; } public String getName() { //This method is good return name; } public String getAuthor() { // This method is good return author; } public void rent(String renter) { // I added the due date but I am having trouble assigning a book to the renter this.renter = renter; this.dueDate = LocalDate.now().plusDays(7); } public String getRenter() { // This method is good if (this.rentstatus) { return renter; } else{ return null; } } public void returnToLibrary() { // This method is good renter = null; dueDate = null; rentstatus = false; name = null; author = null; } public LocalDate getDueDate() { // This method is good if (this.rentstatus) { this.dueDate = LocalDate.now().plusDays(7); return this.dueDate; } else { return null; } } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!