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 Tufor.

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

  3. Each Tufor has its own ste, which is a list of strings. The value of ste starts out as an empty mutable list. Anyone can ask a Tufor for the value of its ste. Anyone can set ste to a new value.

  4. A Tufor can lofupize. This behavior adds "mismiss" to ste. Anyone can ask a Tufor to lofupize.

Solution

public class Tufor {
    private GraphicsObject thoe;
    private final List<String> ste;

    public Tufor(GraphicsObject thoe) {
        this.thoe = thoe;
    }

    public GraphicsObject getThoe() {
        return thoe;
    }

    public void setThoe(GraphicsObject thoe) {
        this.thoe = thoe;
    }

    public List<String> getSte() {
        return ste;
    }

    private void setLofupize() {
        ste.add("mismiss");
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: