We want to realize a program to handle a document archive. For each document the following information is stored: name of the author, title of the document, and number of available copies.
Write a class
Document that implements the following methods:
Document(String a, String t): costructor that, given author and title, constructs a document for which the number of available copies is 0;
String toString(): that returns a string with all the information about the document;
void createCopies(int n): that increments by
nthe number of available copies;
void sellCopies(int n): that decrements by
nthe number of available copies; (if
nis greater than the number of available copies, then such number should become 0);
String getAuthor(): that returns the name of the author of the document;
String getTitle(): that returns the title of the document;
int getCopies(): that returns the number of available copies of the document.
Write a class
UseDocument, client of
contains the following public static methods:
static String authorMaxCopies(Document d1, Document d2): that, given two documents
d2, returns the author of the document among
d2for which more copies are available. If for both documents the same number of copies is available, the method should return the concatenation of the names of the two authors, separated by
" and ".
static int countCopiesAuthor(Document docs, String auth): that, given an archive
docsof documents, rappresented simply as an array of documents, and an author
auth, returns the total number of copies of all documents with author