Question: I am having some trouble with the methods listed below. Especially those that require you to return a class instead of. For instance, the method
I am having some trouble with the methods listed below. Especially those that require you to return a class instead of.
For instance, the method unisa.Library.Item findItem(java.lang.String id) returns an Item from the Item class, but to write a method locates it based off one part of a longer string in an array is where i am having trouble.
Hopefully this clarifies any questions.
***************************************************************************************************************************************************************************************************
This will be done in the form of a library system that allows users to borrow various items that the library holds. You will be required to create an inheritance structure to contain all the different types of items the library might hold. In this case there are five different types of items Books, Magazines, Blurays, DVDs and MusicCDs. You are required to create a library class that manages this system allowing an item to be added or removed in addition to allowing a person to borrow an item and return it. This program is supplied with an incomplete testing program, you must complete the test driver to ensure the completeness of your library system. You are also required to generate the rest of the classes to describe the items held in your library using a suitable inheritance model in your program. Description of the library system There are a number of different types of items in the library. There are Books, Magazines, MusicCDs and Movies. Movies in turn can be DVDs or Blurays. You will need to implement these items as an inheritance structure with appropriate setter and getter methods in addition to appropriate access permissions. As a starting point: All items contain an id (String), a name (String), loaned (boolean), borrower (Person), and a cost (double). All Books will have an author (String) All Magazines will have distributionCity (String) and a magazineFrequency (Frequency) based on an enumerated type which has day, week monthly, quarterly and yearly. All Movies will have an genre (Genre) based on an enumerated type Genre which has scifi, action, drama and romance All DVDs will have a region (int) All Blurays will have region (char) All MusicCD's will have composer (String) and an artist (String) In addition to the Library class described, there are also a few other classes needed for this assignment: A Library contains the list of items (ArrayList of Items) currently held by the library A Person has a name (String) and an address (String). Library items can be borrowed by a person.
-
Restrictions
There are a number of rules you must follow when addressing the requirements for this assignment.- You must use inheritance.
- You must have all the named classes (Library, Person, TestDriver and the two Exception objects).
- Your Library class must have the methods EXACTLY as specified.
- Ill say this one again Your Library class must have the methods EXACTLY as specified. If you don't it wont compile when I dump my testing class in the folder and you will fail the assignment.
-
Class Library Specification
- java.lang.Object
-
- unisa.library.Library
-
public class Library extends java.lang.Object
This class runs the library system and contains a reference to a list of items that are held within the library. This list (called itemList) is of type ArrayList that contains all the items in the library. This library will contain the following types of items. Books Magazines DVDs (Movie) Blurays (Movie) MusicCD Each of these items will need to be stored in the array list (itemList). This list of items can then be manipulated by the methods specified in this document.
Author:
You!!! (Change this in the source code)
-
-
Field Summary
Fields Modifier and Type Field and Description private int count count of all the items in the library.
private java.util.ArrayList itemList itemList contains the List of all items in the library.
-
Constructor Summary
Constructors Constructor and Description Library()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description void addItem(unisa.library.Item newItem) Add a new item to the list of library items.
int countBorrowed() Return the total number of items out on loan.
int countMovies() Return the number of Items that are either Blurays or DVDs
unisa.library.Item findItem(java.lang.String id) Find the item by the given ID and return that Item
unisa.library.Person getBorrower(java.lang.String id) Gets the borrower of an item.
java.lang.String IDForName(java.lang.String name) Returns the id of the library item based on the name given.
boolean isBorrowed(java.lang.String id) Checks if a specific library item is borrowed.
void loanItem(java.lang.String id, unisa.library.Person newPerson) Changes the status of the named item to borrowed and adds the Person to the borrowed
java.lang.String nameForID(java.lang.String id) Look up the name of the library item based on the ID given.
double percentageBorrowed() The percentage of the number of items that are out on loan.
unisa.library.Person returnItem(java.lang.String id) Changes the status of the named item to not borrowed and removes the user from the item.
java.lang.String toString() Convert the entire library to a string.
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
itemList
private java.util.ArrayList itemList
itemList contains the List of all items in the library.
-
count
private int count
count of all the items in the library.
-
-
Constructor Detail
-
Library
public Library()
-
-
Method Detail
-
loanItem
public void loanItem(java.lang.String id, unisa.library.Person newPerson) throws unisa.library.ItemNotFoundException
Changes the status of the named item to borrowed and adds the Person to the borrowed
Parameters:
id - The ID of the item to be borrowed
newPerson - The borrower of the item
Throws:
unisa.library.ItemNotFoundException - thrown if the id is not found.
-
returnItem
public unisa.library.Person returnItem(java.lang.String id) throws unisa.library.ItemNotFoundException
Changes the status of the named item to not borrowed and removes the user from the item. The borrower (person) is returned to the caller
Parameters:
id - The id of the item
Returns:
The person who borrowed the item
Throws:
unisa.library.ItemNotFoundException - thrown if the id is not found.
-
findItem
public unisa.library.Item findItem(java.lang.String id) throws unisa.library.ItemNotFoundException
Find the item by the given ID and return that Item
Parameters:
id - The item to be returned
Returns:
The item searched for.
Throws:
unisa.library.ItemNotFoundException - thrown if the id is not found.
-
getBorrower
public unisa.library.Person getBorrower(java.lang.String id) throws unisa.library.ItemNotFoundException
Gets the borrower of an item. If the item is not found throw ItemNotFoundException.
Parameters:
id - the id of the item
Returns:
the borrower of the item. returns null if the item exists but is not borrowed.
Throws:
unisa.library.ItemNotFoundException - thrown if the id is not found
-
nameForID
public java.lang.String nameForID(java.lang.String id)
Look up the name of the library item based on the ID given.
Parameters:
id - The id of item searched for.
Returns:
The name of the item blank if not found.
-
IDForName
public java.lang.String IDForName(java.lang.String name)
Returns the id of the library item based on the name given.
Parameters:
name - the name of the item
Returns:
the id of the item blank if not found.
-
addItem
public void addItem(unisa.library.Item newItem) throws unisa.library.DuplicateItemException
Add a new item to the list of library items.
Parameters:
newItem - The new item to be added to the list.
Throws:
unisa.library.DuplicateItemException - thrown if the item is already in the list.
-
countMovies
public int countMovies()
Return the number of Items that are either Blurays or DVDs
Returns:
the number of blurays and DVDs
-
toString
public java.lang.String toString()
Convert the entire library to a string. This should call the appropriate toString methods of each item in the ArrayList. Should be in the formatMagazine [magazineFrequency=day, distributionCity=San Andreas]Item [id=ID000, name=Vanity Not So Faire, loaned=false, borrower=null, cost=5.95] Magazine [magazineFrequency=day, distributionCity=San Andreas]Item [id=ID001, name=Click, loaned=false, borrower=null, cost=5.95] Magazine [magazineFrequency=day, distributionCity=San Andreas]Item [id=ID002, name=Renovate, loaned=false, borrower=null, cost=5.95] Magazine [magazineFrequency=day, distributionCity=San Andreas]Item [id=ID003, name=Madrid, loaned=false, borrower=null, cost=5.95] Magazine [magazineFrequency=day, distributionCity=San Andreas]Item [id=ID004, name=Bikes, loaned=false, borrower=null, cost=5.95] MusicCD [composer=Rudy Vale, artist=ValenItem [id=ID005, name=Gatewars Soundtrack, loaned=false, borrower=null, cost=19.95]] MusicCD [composer=Rudy Vale The Third, artist=ValenItem [id=ID006, name=Gatewars 2 Soundtrack, loaned=false, borrower=null, cost=19.95]] MusicCD [composer=Rudy Vale Sr, artist=ValenItem [id=ID007, name=Gatewars 3 Soundtrack, loaned=false, borrower=null, cost=19.95]] MusicCD [composer=Rudy Vale Jr, artist=ValenItem [id=ID008, name=Gatewars 4 Soundtrack, loaned=false, borrower=null, cost=19.95]] MusicCD [composer=Not Rudy Vale, artist=ValenItem [id=ID009, name=Gatewars 5 Soundtrack, loaned=false, borrower=null, cost=19.95]] MusicCD [composer=Rudy Vale, artist=Not ValenItem [id=ID0010, name=Gatewars 6 Soundtrack, loaned=false, borrower=null, cost=19.95]] Bluray [region=c, toString()=Movie [genre=drama, toString()=Item [id=ID0011, name=Gatewars 1 Revenge of the Fallen, loaned=false, borrower=null, cost=29.95]]] Bluray [region=c, toString()=Movie [genre=drama, toString()=Item [id=ID0012, name=Gatewars 2 Ponies Are Ridden, loaned=false, borrower=null, cost=29.95]]] Bluray [region=c, toString()=Movie [genre=drama, toString()=Item [id=ID0013, name=Gatewars 3 Sequels are Lame, loaned=false, borrower=null, cost=29.95]]] Bluray [region=c, toString()=Movie [genre=drama, toString()=Item [id=ID0014, name=Gatewars 3 But They Keep Making Them, loaned=false, borrower=null, cost=29.95]]] Bluray [region=c, toString()=Movie [genre=drama, toString()=Item [id=ID0015, name=Gatewars 5 They Make More Than is Reasonable, loaned=false, borrower=null, cost=29.95]]] DVD [region=1, toString()=Movie [genre=scifi, toString()=Item [id=ID0016, name=Darth Yobbit and the Range Runners, loaned=false, borrower=null, cost=29.95]]] DVD [region=1, toString()=Movie [genre=scifi, toString()=Item [id=ID0017, name=Darth Yobbit and the Long Jumpers, loaned=false, borrower=null, cost=29.95]]] DVD [region=1, toString()=Movie [genre=scifi, toString()=Item [id=ID0018, name=Darth Yobbit and the Domain Walkers, loaned=false, borrower=null, cost=29.95]]] DVD [region=1, toString()=Movie [genre=scifi, toString()=Item [id=ID0004, name=Darth Yobbit and the KiloByte, loaned=false, borrower=null, cost=29.95]]] DVD [region=1, toString()=Movie [genre=scifi, toString()=Item [id=ID0019, name=Darth Yobbit and the Rabbits, loaned=false, borrower=null, cost=29.95]]] Book [author=Arthur C Clarke]Item [id=ID0020, name=The City and The Stars, loaned=false, borrower=null, cost=14.5] Book [author=Arthur C Clarke]Item [id=ID0021, name=Rendevous With Rama, loaned=false, borrower=null, cost=14.5] Book [author=Arthur C Clarke]Item [id=ID0022, name=2001, loaned=false, borrower=null, cost=14.5]
Overrides:
toString in class java.lang.Object
-
isBorrowed
public boolean isBorrowed(java.lang.String id) throws unisa.library.ItemNotFoundException
Checks if a specific library item is borrowed.
Parameters:
id - The id of the item that is to be checked.
Returns:
the status of the item whether it is borrowed or not.
Throws:
unisa.library.ItemNotFoundException - thrown if the id is not found.
-
countBorrowed
public int countBorrowed()
Return the total number of items out on loan.
Returns:
The number representing the number of items currently on loan
-
percentageBorrowed
public double percentageBorrowed()
The percentage of the number of items that are out on loan. Expressed as a percentage of borrowed to total number of items.
Returns:
the percentage borrowed.
-
-
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
