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

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

Solution

public class Snec {
    private GraphicsObject seIalso;

    public Snec(GraphicsObject seIalso) {
        this.seIalso = seIalso;
    }

    public GraphicsObject getSeIalso() {
        return seIalso;
    }

    public void setSeIalso(GraphicsObject seIalso) {
        this.seIalso = seIalso;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: