Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help in java Implement DataSetBook as specified and a test class containing a main method for DataSetBook. Class DataSetBook java.lang.Object DataSetBook public class DataSetBook

Need help in java Implement DataSetBook as specified and a test class containing a main method for DataSetBook. Class DataSetBook java.lang.Object DataSetBook public class DataSetBook extends java.lang.Object A simple store for Book objects. Constructors Constructor and Description DataSetBook() Type Method and Description boolean add(Book objToAdd) // Add a Book to the store Book getMax() // Determine the Book with the most pages Book getMin() //Determine the Book with the fewest pages int size() //The number of Books currently in the store java.lang.String toString() // A String representation of the store. Methods inherited from class java.lang.Object equals, getClass, hashCode, notify, notifyAll, wait, wait, wait Constructor Detail: DataSetBook public DataSetBook() //Default constructor Method Detail : add: public boolean add(Book objToAdd) // Add a Book to the store ,Parameters:(objToAdd) - Returns:true if the element was added to the collection, false otherwise size: public int size() //The number of Books currently in the store Returns:number of Book objects getMin public Book getMin() //Determine the Book with the fewest pages Returns:null if the store is empty. The book with the fewest pages otherwise. If more than one book has the fewest number of pages, the first one is returned. getMax: public Book getMax() //Determine the Book with the most pages Returns:null if the store is empty. The book with the most pages otherwise. If more than one book has the most number of pages, the first one is returned. toString: public java.lang.String toString() //A String representation of the store. Overrides:toString in class java.lang.ObjectReturns:A String containing the number of books in the store, the minimum book, the largest book, and the contents of the entire store. Class Book java.lang.Object Book public class Book extends java.lang.Object Constructor and Description: Book(java.lang.String auth, java.lang.String titl, int pag) Type Method and Description boolean equals(java.lang.Object obj) int getPages() java.lang. String toString() Methods inherited from class java.lang.Object getClass, hashCode, notify, notifyAll, wait, wait, wait Constructor Detail Book public Book(java.lang.String auth, java.lang.String titl, int pag) Method Detail: getPages: public int getPages() toString public java.lang.String toString() :Overrides: toString in class java.lang.Object equals: public boolean equals(java.lang.Object obj) Overrides:equals in class java.lang.Object

This is what was given:

public class Book { private String author; private String title; private int pages;

public Book(String auth, String titl, int pag) { author = auth; title = titl; pages = pag; }

public int getPages() { return pages; }

@Override public String toString() { return "Book [author=" + author + ", title=" + title + ", pages=" + pages + "] "; }

// this is a really poor way to compare Book objects, but it will work for us /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Book other = (Book) obj; if (author == null) { if (other.author != null) return false; } else if (!author.equals(other.author)) return false; if (pages != other.pages) return false; if (title == null) { if (other.title != null) return false; } else if (!title.equals(other.title)) return false; return true; }

}

Need the DataSetBook program exactly as described above with comments and a Test Program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions