So I have and interface that is implemented by a class called Vehicle that accepts a double value as the parameter:
public class Vehicle implements Efficiency
{
//instance variable
private double efficiency;
public Vehicle(double x)
{
//parameter initializes the instance variable
x = efficiency;
}
This is the interface:
public interface Efficiency
{
double getEfficiency();
}
I need to create a method called getFirstBelowT() that accepts an Efficiency array and a double as parameters. The method is supposed to return an Efficiency object that is the first object in the array that is less than the double value in the parameter. How can I compare the elements in the Efficiency array to the double value? This is what I have so far:
//a method that returns an Efficiency object that is the first
//object in the array with a efficiency below the double parameter
public static Efficiency getFirstBelowT(Efficiency[] x, double y)
{
//loop through each value in the array
for(Efficiency z: x)
{
//if the value at the index is less than the double
if(z < y)
{ //returns the first value that is less than y and stops looping
// through the array.
return z;
break;
}
}
//returns null if none of the element values are less than the double
return null;
}
efficiency = xwould initialize the member variable, you are overwriting the parameter value with zero.