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

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

Solution

public class Haur {
    private GraphicsObject echan;

    public Haur(GraphicsObject echan) {
        this.echan = echan;
    }

    public GraphicsObject getEchan() {
        return echan;
    }

    public void setEchan(GraphicsObject echan) {
        this.echan = echan;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: