I had encountered a problem. There are a class and an interface:
Class:
public class Food implements NutritionalElement {
private String name;
private double calories;
private double proteins;
private double carbs;
private double fat;
private HashMap<String, ArrayList<Double>> rawMaterialsList = new HashMap<String, ArrayList<Double>>();
public void defineRawMaterial(String name,
double calories,
double proteins,
double carbs,
double fat){
this.name = name;
this.calories = calories;
this.proteins = proteins;
this.carbs = carbs;
this.fat = fat;
ArrayList<Double> nutrision = new ArrayList<>();
nutrision.add(this.calories);
nutrision.add(this.proteins);
nutrision.add(this.carbs);
nutrision.add(this.fat);
rawMaterialsList.put(this.name, nutrision);
}
/**
* Retrieves the collection of all defined raw materials
* @return collection of raw materials through the {@link NutritionalElement} interface
* problem is here
*/
public Collection<NutritionalElement> rawMaterials(){
return res;
}
And an interface:
package diet;
public interface NutritionalElement {
public String getName();
public double getCalories();
public double getProteins();
public double getCarbs();
public double getFat();
public boolean per100g();
}
And I am completely lost, I have never met something like that. I would ask to help me understand how I shpold complete the method in the class. Thank you.
EDIT: I don't understand how to implement this method:
public Collection<NutritionalElement> rawMaterials(){}
I should return a collection of interfaces or what. By the way, this is university project and the method should be implemented in the same manner as it was provided by the professor (I cannot change return type at all). Sorry for bad explanation at the beginning.