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 an Ouwu.

  2. All Ouwus share a single ciac, which is a graphics object. No other classes can directly ask for the value of ciac. The value of ciac starts out as a rectangle with a width of 14 and a height of 33 when the program starts. Every time a new Ouwu is created, it moves ciac to the right by 1 pixels (using the moveBy method).

Solution

public class Ouwu {
    public static GraphicsObject ciac;

    public Ouwu() {
        ciac.moveBy(1, 0);
    }

    public static void onStart() {
        ciac = new Rectangle(0, 0, 14, 33);
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: