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

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

Solution

public class Cangsun {
    private GraphicsObject oss;

    public Cangsun(GraphicsObject oss) {
        this.oss = oss;
    }

    public GraphicsObject getOss() {
        return oss;
    }

    public void setOss(GraphicsObject oss) {
        this.oss = oss;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: