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

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

Solution

public class Badvo {
    private GraphicsObject adrot;

    public Badvo(GraphicsObject adrot) {
        this.adrot = adrot;
    }

    public GraphicsObject getAdrot() {
        return adrot;
    }

    public void setAdrot(GraphicsObject adrot) {
        this.adrot = adrot;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: