Question
Library Project: Book.java In the project, you will develop four classes called Book, Reader, Shelf, and Library. These classes will be used to store, manipulate,
Library Project: Book.java
In the project, you will develop four classes called Book, Reader, Shelf, and Library. These classes will be used to store, manipulate, and analyze information stored in the library.
This file details the creation of the Book.java class. The UML is listed below.
All the fields have getters and setters. It is also important to note that the class has a hashCode() method and an equals() method.
The constant fields are used to index the values from the library00.csv files as seen below.
Field Details 2
Constant Fields 2
Library00.csv 2
Method Details 3
equals() 3
hashCode() 3
toString() 3
Testing 4
Constructor Test 4
Field Setting and Getter Test 4
Equality Test 4
Setter Test 5
UML Diagram of Book.java 6
Field Details
Constant Fields
ISBN_ TITLE_ SUBJECT_ PAGE_COUNT_ AUTHOR_ DUE_DATE_
These fields will hold an integer that will be used to index the values shown below. The values will be read from a String array that results from using the split() method on the comma separated Strings shown below.
Library00.csv
1337,Headfirst Java,education,1337,Grady Booch,0000
42-w-87,Hitchhikers Guide To the Galaxy,sci-fi,42,Douglas Adams,0000
5297,Count of Monte Cristo,Adventure,999,Alexandre Dumas,0000
42-w-87,Hitchhikers Guide To the Galaxy,sci-fi,42,Douglas Adams,0000
1337,Headfirst Java,education,1337,Grady Booch,0000
34-w-34,Dune,sci-fi,235,Frank Herbert,0000
Method Details
equals()
Use inteliJ to auto generate this.
The equals method will compare everything except the dueDate.
hashCode()
Use inteliJ to auto generate this.
The hashCode method will compare everything except the dueDate.
toString()
The toString will concatenate the title, author, and ISBN in the following order:
[Title] by [Author] ISBN: [isbn]
E.g.
Headfirst Java by Grady Booch ISBN: 1337
Testing
Each class in this project will require unit tests. I will provide less and less instruction for each class as I want you to develop the ability to write tests on your own. The nice thing is, most tests are going to be pretty similar.
A general rule to follow when writing unit tests is to build up based on 'knowns'. What I mean is:
Does the class instantiate?
Once it does we can test the fields
Once we can ensure the fields are set we can test for accuracy
Then we can test for mutability
Then we can test for functionality
Creation Instantiation Mutation Evaluation
Constructor Test
-
Create a Book object and set it to null.
-
Assert that it is null
-
This will ALWAYS pass
-
-
Instantiate the Book with dummy or empty parameters (i.e. "" for a String)
-
book = new Book()
-
-
Assert that it is not null
Field Setting and Getter Test
-
Create variables for each parameter that will be passed in to the constructor.
-
Use AssertEquals for each getter to ensure that the values are set accordingly
-
This has saved my bacon on more than one occasion when I had the parameters in the wrong order
-
Equality Test
-
Create an instance of a Book with given values as we did in Field Setting and Getter Test
-
Create an instance of a Book with DIFFERENT values
-
Ensure that they are NOT equal
-
Create a new instance of Book with the same values as one of the previous
-
Assert that they are equal
-
Note: DO NOT test this: Book book1 = New Book({Parameters}); Book book2 = book1;
-
Setter Test
We now know our getters work. Test the setters.
-
Instantiate a Book like we did in Field setting and Getter Test
-
Declare variables with new values for each parameter
-
Set the values to the new parameter
-
Assert that the values are not equal to the old value
-
Assert that the values ARE equal to the NEW value
UML Diagram of Book.java
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started