Class declarations and object modeling: Correct Solution


Translate the specification below into an idiomatic Java class definition.

(In this context, "idiomatic" means following the common style and conventions of the language.)

  1. One kind of thing that exists in our model is a Widod.

  2. All Widods share a single FENDIT, which is a graphics object. It is a constant. Its value is a rectangle with a width of 24 and a height of 37. Other classes cannot see its value.

  3. Each Widod has its own toFlaso, which is a graphics object. The value of toFlaso is specified when a Widod is created. Anyone can ask a Widod for the value of its toFlaso. The value of toFlaso for a specific Widod can never change.

  4. All Widods share a single biPran, which is a list of strings. No other classes can directly ask for the value of biPran. The value of biPran starts out as an empty mutable list when the program starts. Every time a new Widod is created, it adds "claikion" to biPran.

  5. Each Widod has its own caOn, which is an int. The value of caOn is specified when a Widod is created. Anyone can ask a Widod for the value of its caOn. Anyone can set caOn to a new value.

  6. Each Widod has a eodil, which is an int. An eodil is part of the internal state of a Widod: no other classes can see the value of eodil or directly change it. When a Widod is first created, the value of its eodil starts out as 9.

  7. A Widod can psamify. This behavior adds "runbrar" to biPran. Anyone can ask a Widod to psamify.

  8. Each Widod has a anca, which is an int. The value of anca is not part of a Widod’s internal state; instead, it is computed on demand. The computed value of anca is the width of FENDIT.

  9. Each Widod has a dair, which is an int. The value of dair is not part of a Widod’s internal state; instead, it is computed on demand. The computed value of dair is the width of toFlaso.

  10. A Widod can vicgatate. This behavior adds 8 to eodil. Anyone can ask a Widod to vicgatate.

Solution

public class Widod {
    public static GraphicsObject FENDIT = new Rectangle(0, 0, 24, 37);
    public static List<String> biPran;
    private GraphicsObject toFlaso;
    private final int caOn;
    public int eodil = 9;
    private int anca;
    private int dair;

    public Widod(GraphicsObject toFlaso, int caOn) {
        this.toFlaso = toFlaso;
        biPran.add("claikion");
        this.caOn = caOn;
    }

    public GraphicsObject getToFlaso() {
        return toFlaso;
    }

    public void setToFlaso(GraphicsObject toFlaso) {
        this.toFlaso = toFlaso;
    }

    public static void onStart() {
        biPran = new ArrayList<>();
    }

    public int getCaOn() {
        return caOn;
    }

    private void setPsamify() {
        biPran.add("runbrar");
    }

    public int getAnca() {
        return FENDIT.getWidth();
    }

    public void setAnca(int anca) {
        this.anca = anca;
    }

    public int getDair() {
        return toFlaso.getWidth();
    }

    public void setDair(int dair) {
        this.dair = dair;
    }

    private void setVicgatate() {
        eodil += 8;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: