Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DatSetGeneric.java Please help me the java program? Here is the requirement: Here is the Generics Starter code from the instructor for the program. ---------- Book.java

DatSetGeneric.java

Please help me the java program? Here is the requirement:

image text in transcribed

Here is the Generics Starter code from the instructor for the program.

----------Book.java----------

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; } } 

-------DataSetBook.java---------

import java.util.ArrayList; /**  * A simple store for Book objects.  *  * @author student  *  */ public class DataSetBook { private ArrayList data; /**  * Default constructor  */  public DataSetBook() { data = new ArrayList(); } /**  * Add a Book to the store  *  * @param objToAdd Book to add  */  public void add(Book objToAdd) { data.add(objToAdd); } /**  * The number of Books currently in the store  *  * @return number of Book objects  */  public int size() { return data.size(); } /**  * Determine the Book with the fewest pages  *  * @return 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.  */  public Book getMin() { if (data.isEmpty()) { return null; } Book mEle = data.get(0); for (int i = 1; i  (data.get(i).getPages())) { mEle = data.get(i); } } return mEle; } /**  * Determine the Book with the most pages  *  * @return 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.  */  public Book getMax() { if (data.isEmpty()) { return null; } Book mEle = data.get(0); for (int i = 1; i /**  * A String representation of the store.  *  * @return A String containing the number of books in the store,  * the minimum book, the largest book, and  * the contents of the entire store.  */  @Override public String toString() { return "DataSetBook [ size()=" + size() + " getMin()=" + getMin() + " getMax()=" + getMax() + " Books= " + data.toString() + "]"; } } 

----------Measurable.java---------

public interface Measurable { int getMeasure(); } 
Generics give the application writer compile-time help in keeping boats and buildings out of his book store. A Book and DataSetBook classes and a Measurable interface are provided, but feel free to rewrite them if that seems easier. You may also wish to start from a different version of Dataset; that's up to you. You are to write a generic class DataSetGeneric. DataSetGeneric should provide the usual add, size, getMin, getMax and toString methods. This should be a generic class so that only elements of the specified type are allowed into the data store. All of its elements should implement the Measurable interface, however, that's what you will rely on to implement getMin and getMax Also provide a tester for DataSetGeneric

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

Recommended Textbook for

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

1844804526, 978-1844804528

More Books

Students also viewed these Databases questions

Question

Write down the Limitation of Beer - Lamberts law?

Answered: 1 week ago

Question

Discuss the Hawthorne experiments in detail

Answered: 1 week ago

Question

Explain the characteristics of a good system of control

Answered: 1 week ago

Question

State the importance of control

Answered: 1 week ago

Question

=+2 Is the decision sustainable in the long run?

Answered: 1 week ago