We want to realize a program to handle books rented at a library. For each book the following information is stored: author and title of the book, status of the book (rented or not), name of the person who rented the book.
Parte 1.
Write a class Book
that implements the following methods:
Book(String a, String t)
: constuctor that creates a book
with author a
and title t
that is initially not
rented;
String toString()
: that returns a string with all the
information about the book;
void rentTo(String n)
: that modifies the information about
the book by specifying that the book has been rented by the person whose
name is n
;
void returned()
: that modifies the information about
the book by specifying that it has been returned to the library;
boolean isRented()
: that verifies whether a book is
currently being rented;
String whoHasBook()
: that returns the name of the person
that currently rents the book, or null
if the book is
currently not rented;
String getAuthor()
: that returns the author of the book;
String getTitle()
: that returns the title of the book;
Example program:
TestBook.java
Part 2.
Write a class UseBook
, client of Book
, that contains
the following public static methods:
static int countAvailableBooks(Book b1, Book b2, Book b3)
: that, given three books b1
, b2
, and
b3
, returns the number of books among b1
,
b2
, and b3
that are currently not rented.
static int countRentedBooks(Book[] b, String a)
:
that, given an archive arch
of books, rappresented
simply as an array of books, and the name auth
of an author,
returns the number of books of the author auth
in
arch
that are currently rented.
Example program:
TestUseBook.java
Solutions:
Book.java
,
UseBook.java