MeasurableTester.java /** This program demonstrates the measurable Country class. Difficulty: Easy */ public class MeasurableTester { public
Question:
MeasurableTester.java
/**
This program demonstrates the measurable Country class.
Difficulty: Easy
*/
public class MeasurableTester
{
public static void main(String[] args)
{
Measurable[] countries = new Measurable[3];
countries[0] = new Country("Uruguay", 176220);
countries[1] = new Country("Thailand", 513120);
countries[2] = new Country("Belgium", 30510);
Measurable maxCountry = Measurable.largest(countries);
System.out.println("Maximum area: " + maxCountry.getMeasure());
System.out.println("Expected:Maximum area: 513120.0");
Measurable minCountry = Measurable.smallest(countries);
System.out.println("Minimum area: " + minCountry.getMeasure());
System.out.println("Expected:Minimum area: 30510.0");
}
}
Country.java
public class Country implements Measurable
{
private String name;
private double area;
/**
Construct a country with name and area.
@param name country's name
@param area total area of country
*/
public Country(String name, double area)
{
this.name = name;
this.area = area;
}
/**
Measurable interface method to retrieve measure.
@return the measured area
*/
//-----------Start below here. To do: approximate lines of code = 2
//
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
Measurable.java
public interface Measurable
{
double getMeasure();
/**
Computes the smallest of the measures of the given objects.
@param objects an array of Measurable objects
@return the object with the smallest measure, null if array is empty
*/
static Measurable smallest(Measurable[] objects)
{
if (objects.length == 0)
{
return null;
}
Measurable min = objects[0];
for (Measurable obj : objects)
{
if (obj.getMeasure() < min.getMeasure())
{
min = obj;
}
}
return min;
}
/**
Computes the largest of the measures of the given objects.
@param objects an array of Measurable objects
@return the object with the largest measure, null if array is empty
*/
static Measurable largest(Measurable[] objects)
{
if (objects.length == 0)
{
return null;
}
Measurable max = objects[0];
for (Measurable obj : objects)
{
if (obj.getMeasure() > max.getMeasure())
{
max = obj;
}
}
return max;
}
}
P.s: please besides the code, also include a screenshot of code, and the output to confirm code doesn't get edited out and the output satisfies the problem!!
Financial accounting
ISBN: 978-0136108863
8th Edition
Authors: Walter T. Harrison, Charles T. Horngren, William Bill Thomas