Hi friends!
I'm trying to do my homework. Now I am busy with the Cone.java part.
(F) balls >>> Flavor[]
How can I define that?
Hi friends!
I'm trying to do my homework. Now I am busy with the Cone.java part.
(F) balls >>> Flavor[]
How can I define that?
Well to break it down a bit for you.
Cone is a class that implements Eatable.
It has a field called balls. This is an array of type Flavors.
It also has two constructors. A basic constructor that has no arguments and a constructor that takes an array of type Flavors.
Finally it has a method called eat. This comes from the interface Eatable.
This would look a little like the following.
Eatable.java
public interface Eatable {
    void eat();
}
Cone.java
public class Cone implements Eatable {
    //The types of flavors
    public enum Flavors {
        STRAWBERRY,
        BANANA,
        CHOCOLATE,
        VANILLA,
        LEMON,
        STRACIATELLA,
        MOKKA,
        PISTACHE
    }
    //The field
    private Flavors[] balls;
    //The constructors
    //Constructor Basic
    public Cone() {
        balls = new Flavors[0];
    }
    //Constructor with Flavors
    public Cone(Flavors[] balls) {
        this.balls = balls;
    }
    //The methods
    //You should always use getters and setters
    //https://stackoverflow.com/questions/1568091/why-use-getters-and-setters-accessors
    //Getter
    public Flavors[] getBalls() {
        return balls;
    }
    //Setter
    public void setBalls(Flavors[] balls) {
        this.balls = balls;
    }
    //Your method from UML
    @Override
    public void eat() {
        //Whatever
    }
}
 
    
    This is simply a Dependency relation. You need to draw a dashed arrow from Cone to Flavor. This is because Flavor is an enumeration (the Mickeysoft or Eclipse notation you're using is wrong by the way, but you probably can't alter that except by staying away from the tool itself). The enumeration is used for balls to form an array of Flavors.
