Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create an interface Measurable that has a single method: int getMeasure() Rewrite our old friend DataSetBook . Change its name to DataSetMeasurable . Replace all

Create an interface Measurable that has a single method: int getMeasure()

Rewrite our old friend DataSetBook. Change its name to DataSetMeasurable. Replace all references to Book objects with Measurable objects.

To test your DataSetMeasurable, write two or more classes that implement Measurable. (I suggest keeping them very simple.) Write a tester that puts instances of both Measurable classes into a DataSetMeasurable.

Notice that DataSetBook could store only Book objects. But DataSetMeasurable can store anything implementing Measurable. If I have a Building class implementing Measurable, and a HeatSensor implementing Measurable, I can put Buildings and HeatSensors into one DataSetMeasurable object. Doing that probably isn't rational, but DataSetMeasurable is much more flexible than DataSetBook; so long as the objects we add to it are Measurable, it doesn't care if the application using it is sensible or not.

The starter file is the same one from our Inheritance lesson. You may start with this starter code or may start from your solution to the Inheritance lab. Either is acceptable.

we have already thoes cods :

package lab_start;

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 + "] "; }

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

}

package lab_start;

import java.util.ArrayList;

public class DataSetBook { private ArrayList data;

public DataSetBook() { data = new ArrayList<>(); } public boolean add(Book objToAdd) { return data.add(objToAdd); } public int size() { return data.size(); } public Book getMin() { if (data.isEmpty()) { return null; } Book mEle = data.get(0); for (int i = 1; i < data.size(); i++) { if (mEle.getPages() > (data.get(i).getPages())) { mEle = data.get(i); } } return mEle; }

public Book getMax() { if (data.isEmpty()) { return null; } Book mEle = data.get(0); for (int i = 1; i < data.size(); i++) { if (mEle.getPages() < (data.get(i).getPages())) { mEle = data.get(i); } } return mEle; }

@Override public String toString() { return "DataSetBook [ size()=" + size() + " getMin()=" + getMin() + " getMax()=" + getMax() + " Books= " + data.toString() + "]"; } }

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_2

Step: 3

blur-text-image_3

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

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions

Question

=+ Who do you think is right? Why?

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago