Question: Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable in the class definition. Now, all book
Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable
1. Use Arrays.sort( Book[] books) from the java util package to sort the array. The order of objects in the array is determined using compareTo(...) method.
2. Write a method that returns the most expensive book in the array of objects (Books).
- The method signature is: public static Book max ( Book[] books)
3. Create another class BookTitleComparator that implements the Comparator interface in which overside the compare( Book a, Book b) method. Use the implements Comparator
4. Using Arrays.sort( Book[] books, new BookTitleComparator() ) to sort books by the title.
- Arrays.sort ( books, new BookTitleComparator() );
5. Create a method to show each element in the array with the following method signature:
- public static void showBooksArray ( books )
Book MyDate itle:String author: ArrayList Author publishing: MyDate price : Double 01MDate from assignment 4 Bookf tite:String, author Author, publiching:MyDate, price: Doublel setTielel title: String): void setAuthorl title: String):wold setDate date: MyDate | : vold getDate(): MyDate +setPricel price: int: void getprice } : imt compareTol book: Book ): int toStringl): String 1 Author seweak name : String Aray List Book Athorl name:String age int getName): String setNametnmeStringl : oid + getaged: String + setAgelageint): vold + petBooki title : String : Book + setBookl book:Book: void +toString):String + compare( book1:Book, book2: Book] : int Class MyDate should have member of type Date and provide methods and constructor to allow User to create object of myDate
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
