Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DataSetMeasurable Can you please help me the JAVA program? Here is the requirment. Create an interface Measurable that has a single method: int getMeasure() Rewrite

DataSetMeasurable

Can you please help me the JAVA program? Here is the requirment.

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

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

To test DataSetMeasurable, write two or more classes that implement Measurable. (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.

--------------here is Book.java code-------------------

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; import java.util.Arrays;

public class DataSetBook extends ArrayList { public DataSetBook(){ } public boolean add(Book objToAdd){ return super.add(objToAdd); } public int size(){ return super.size(); } public Book getMin(){ int size = super.size(); if(size == 0){ return null; } else{ Book minBook = super.get(0); for(int i=0; i b.getPages()){ minBook = super.get(i); } } return minBook; } } public Book getMax(){ int size = super.size(); if(size == 0){ return null; } else{ Book maxBook = super.get(0); for(int i=0; i

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

Students also viewed these Databases questions