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

  2. All Stickbects share a single tadi, which is a graphics object. No other classes can directly ask for the value of tadi. The value of tadi starts out as a rectangle with a width of 41 and a height of 28 when the program starts. Every time a new Stickbect is created, it moves tadi to the right by 6 pixels (using the moveBy method).

Solution

public class Stickbect {
    public static GraphicsObject tadi;

    public Stickbect() {
        tadi.moveBy(6, 0);
    }

    public static void onStart() {
        tadi = new Rectangle(0, 0, 41, 28);
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: