Question: Step 1 : The Book Class Write a Book class that stores two fields: the book title; the Year in which the book was released.
Step : The Book Class
Write a Book class that stores two fields:
the book title;
the Year in which the book was released.
Be sure these fields are marked private, and provide getter methods for each one.
Now provide a constructor that accepts as parameters in this order:
the title
the releaseYear type: Year
Initialize both of these fields in the constructor and make the Book class implement Comparable ie: you want the Books to have some natural ordering When you go to implement the required compareTo method, do the comparison on the basis of the book's release year.
Next, override toString to render the book like so: titlereleaseYear
You'll also need to override the following methods:
@Override public boolean equalsObject o todo
@Override public int hashCode todo
@Override public int compareToBook o todo
The equals method should use releaseYear and title as significant fields for determining equality use these fields to compute the hash value as well in hashCode
Practice writing equals yourself, don't use the IntelliJ generated version please.
Step : Tester class static methods
upDownOrNeither: Next, complete the static method upDownOrNeither. The method should be parameterized by a generic type T that extends Comparable consult the chapter for syntax on this The method should take four formal parameters: t t t and t each of type T; the int returned by the method should be:
if the parameters t t t and t are in ascending up order,
if all parameters are in descending down order and,
if the parameters are unordered neither
Hint: since the type variable T is 'bounded' by Comparable you can call compareTo on variables of type T For example, tcompareTot etc. Review the compareTo method contract if needed you can find it in the Comparable interface
rmDupsPreservingOrder: This method is provided for you, though the tests will only pass assuming you've implemented equals and hashCode correctly for the book class.
Here are some examples of this method in action removes duplicates while preserving the original order:
rmDupsPreservingOrder List.of prints:
rmDupsPreservingOrder List.of prints:
See the Tester class for an example involving the Book class.
Step : More testing code add to top of main method
Add the following to the top of the main method you'll need to print each one out:
upOrDownOrNeitheradbg; neither should print upOrDownOrNeither; upincreasing should print upOrDownOrNeither; downdecreasing should print upOrDownOrNeithercdhi; up should print upOrDownOrNeithercdha; neither should print upOrDownOrNeither Year.of Year.of Year.of Year.of; down should print
Step Optional: Checking Sameness
Implement another static generic method in the Tester class called sameEntries. The method should be parameterized by a single generic type T and should take a List source as a parameter, and return true if all entries in source are the same; false otherwise.
Challenge: try to do this method in or lines of code.
THIS IS THE EXPECTED OUTPUT ALL LINES ARE NECESSARY TO PASS NOT JUST THE FIRST COUPLE OR LAST FEW. ALL LINES. PLEASE SEE BELOW AND LOOK THROUGHLY BEFORE SUBMITTING AN ANSWER.
Expected Output:
A B B C X Y
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
