Question: I need help wioth my code please public interface Measurable { double getMeasure ( ) ; } public class Country implements Measurable { private String

I need help wioth my code please
public interface Measurable {
double getMeasure();
}
public class Country implements Measurable {
private String name;
private double area;
public Country(String name, double area){
this.name = name;
this.area = area;
}
public String getName(){
return name;
}
public double getArea(){
return area;
}
@Override
public double getMeasure(){
return getArea();
}
}
public class Util {
public static double average(Measurable[] objects){
double sum =0;
for (Measurable obj : objects){
sum += obj.getMeasure();
}
return objects.length >0? sum / objects.length : 0;
}
}
public class AverageArrayTester {
public static void main(String[] args){
Measurable[] countries = new Measurable[]{
new Country("Country A",30000.0),
new Country("Country B",40000.0),
new Country("Country C",50000.0)
};
double averageArea = Util.average(countries);
System.out.println("The average area is: "+ averageArea);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!