import java.util.Arrays;
import java.util.List;
class Info {
private Double distanceKm;
private Double fuel;
public Info(Double distanceKm, Double fuel) {
this.distanceKm = distanceKm;
this.fuel = fuel;
}
public double getDistanceKm() {
return distanceKm;
}
public double getFuel() {
return fuel;
}
}
public class Main {
public static void main(String []args) {
List<Info> valuesFromECU = Arrays.asList(
new Info[]{
new Info(10.0, 1.0),
new Info(10.5, 1.0),
new Info(11.2, 1.0),
new Info(15.0, 1.5),
new Info(20.0, null),
new Info(21.0, 2.1),
});
for (Info info : valuesFromECU) {
double consumption =info.getDistanceKm()/info.getFuel();
System.out.println("Your car has a fuel consumption of " + consumption + " kilometers per litre");
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: