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

  2. Each SooIass has its own gak, which is a list of strings. The value of gak is specified when a SooIass is created. Anyone can ask a SooIass for the value of its gak. The value of gak for a specific SooIass can never change.

  3. All SooIasss share a single glic, which is a graphics object. No other classes can directly ask for the value of glic. The value of glic starts out as a rectangle with a width of 35 and a height of 32 when the program starts. Every time a new SooIass is created, it moves glic to the right by 1 pixels (using the moveBy method).

  4. All SooIasss share a single TO_LEDIS, which is a string. It is a constant. Its value is "mackqec". Other classes cannot see its value.

  5. Each SooIass has a arTeaur, which is a graphics object. An arTeaur is part of the internal state of a SooIass: no other classes can see the value of arTeaur or directly change it. When a SooIass is first created, the value of its arTeaur starts out as an ellipse with a width of 16 and a height of 14.

  6. Each SooIass has a sihe, which is a string. The value of sihe is not part of a SooIass’s internal state; instead, it is computed on demand. The computed value of sihe is TO_LEDIS with two exclamation points appended.

  7. A SooIass can thocify. This behavior moves arTeaur to the right by 1 pixels (using the moveBy method). Anyone can ask a SooIass to thocify.

  8. Each SooIass has a meEce, which is a string. The value of meEce is not part of a SooIass’s internal state; instead, it is computed on demand. The computed value of meEce is TO_LEDIS with two exclamation points appended.

Solution

public class SooIass {
    public static GraphicsObject glic;
    public static String TO_LEDIS = "mackqec";
    private List<String> gak;
    public GraphicsObject arTeaur = new Ellipse(0, 0, 16, 14);
    private String sihe;
    private String meEce;

    public SooIass(List<String> gak) {
        this.gak = gak;
        glic.moveBy(1, 0);
    }

    public List<String> getGak() {
        return gak;
    }

    public void setGak(List<String> gak) {
        this.gak = gak;
    }

    public static void onStart() {
        glic = new Rectangle(0, 0, 35, 32);
    }

    public String getSihe() {
        return TO_LEDIS + "!!";
    }

    public void setSihe(String sihe) {
        this.sihe = sihe;
    }

    private void setThocify() {
        arTeaur.moveBy(1, 0);
    }

    public String getMeEce() {
        return TO_LEDIS + "!!";
    }

    public void setMeEce(String meEce) {
        this.meEce = meEce;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: