Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java and use the testcodes and author class to do the Book class and A2Exercises undefined * 1 public class A2Exercises ! 2 3 4
Java and use the testcodes and author class to do the Book class and A2Exercisesundefined
* 1 public class A2Exercises ! 2 3 4 * Purpose: Add b to the given array of books 5 * Parameters: Book[] array the array to add the book to 6 Book b - the book to add to the array 7 * Returns: Book [] a new array containing all of the books 8 found in arr plus book b 9 */ 10 public static Book[] addBook (Book[] array, Book b) { 11 // Fix me! 12 Book[] result = null; 13 return result; // so it compiles 14 } 15 16 /* * Purpose: get the sum of all the page counts from all of the books in the array 18 * Parameters: Book[] array 19 * Returns: int - the total number of pages found in all books in the array 20 21 public static int numberOfPages (Book[] array) { 22 // Fix me! 23 int result = 0; 24 return result; // so it compiles 25 } 26 27 /* 28 * Purpose: get the number of books in the array 29 with a rating equal to the given rating 30 * Parameters: Book[] arr - the array of books 31 int rating - the rating to search for 32 * Returns: int the number of books with the given rating 33 */ public static int booksWithRating (Book[] arr, int rating) { // Fix me! int result = 0; 37 return result; // so it compiles } O 000 UTAWNO 000 UA WNA */ * * 34 35 36 public class Author { private String firstName; private String lastName; private int age; public Author(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; this.age = 0; } public Author(String firstName, String lastName, int age) { this.firstName = firstName; this.lastName = lastName; this.age = age; } 6 9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 public String getFirstName() { return this.firstName; } public String getLastName() { return this.lastName; } public int getAge() { return this.age; } public boolean equals (Author other) { return this.firstName.equals (other.getFirstName()) && this.lastName.equals (other.getLastName()) && this.age other.getAge(); } == Oh public boolean olderThan (Author other) { return this. age > other.getAge(); } -}| public class Book { private String title; private Author author; private int rating; private int totalPages; public Book (String title, Author author, int rating, int totalPages) { this.title = "unknown"; this.author = null; this.rating = 0; this.totalPages 0; } public Author getAuthor() { return author; } public int getTotalPages() { return totalPages; } public int getRating () { return rating; } /* * Purpose: determine if the current book is equal to other * Parameters: Book other - the other book to compare to * Returns: boolean - true if the two books have the same title and author (the same book might have a different number of pages depending on whether the copy is hard-cover or paperback, and might receive different ratings from different reviewers). */ public boolean equals (Book other) { return false; // so it compiles } /* * Purpose: determine the percentage the book has been read * Parameters: int pagesRead - the number of pages read in this book * Returns: double - the percentage of the way the reader has progressed through the book. */ public double percentageRead (int pagesRead) { return 0.0; // so it compiles UTStep 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