Question: Question Description MeasurableTester.java /** This program demonstrates the measurable Country class. Difficulty: Easy */ public class MeasurableTester { public static void main(String[] args) { Measurable[]

Question Description

See the following files: *MeasurableTester.java * Country.java (has todo) * Measurable.java Approximate

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 = 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!!

See the following files: *MeasurableTester.java * Country.java (has todo) * Measurable.java Approximate total lines of code required: 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The detailed answer for the above question is provided below Your Answer MeasurableTesterjava public ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!