1

UML Diagram

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?

Dan
  • 7,286
  • 6
  • 49
  • 114
Atilla
  • 59
  • 1
  • 6
  • 1
    Welcome to stackoverflow. Your question is very unspecific, try to add more information and have a look at [this](https://stackoverflow.com/help/how-to-ask). – SeleDry Jun 30 '18 at 08:33
  • @Atilla Did my answer answer your question or were you struggling with something else? – Dan Jul 01 '18 at 19:00
  • I've solved this issue . Thanks everyone! – Atilla Jul 01 '18 at 19:23

2 Answers2

0

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
    }
}
Dan
  • 7,286
  • 6
  • 49
  • 114
  • https://github.com/injecti0n/IceCreamShop I've done with the project but i have still compiler error ... Can you please check my code? – Atilla Jul 01 '18 at 19:24
  • @Atilla Sure, give me a minute – Dan Jul 01 '18 at 19:43
  • @Atilla I just ran it in Eclipse and there seemed to be no compilation issues. There is still an exception being thrown but that is your own exception so I assume you are handling that how you want – Dan Jul 01 '18 at 19:48
  • @Atilla Let me know if there is another issue. In the meantime if either me or Thomas answered your question to your satisfaction would you be able to hit the tick on one of our answers? It lets others know the issue has been resolved. Thanks :) – Dan Jul 01 '18 at 19:54
0

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.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86