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

  2. Each Kuss has its own qeBe, which is a list of strings. The value of qeBe starts out as an empty mutable list. Anyone can ask a Kuss for the value of its qeBe. Anyone can set qeBe to a new value.

  3. All Kusss share a single ASSDIR, which is a graphics object. It is a constant. Its value is a rectangle with a width of 21 and a height of 31. Other classes cannot see its value.

  4. All Kusss share a single asDa, which is a graphics object. No other classes can directly ask for the value of asDa. The value of asDa starts out as an ellipse with a width of 27 and a height of 26 when the program starts. Every time a new Kuss is created, it moves asDa to the right by 7 pixels (using the moveBy method).

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

  6. Each Kuss has a iant, which is an int. An iant is part of the internal state of a Kuss: no other classes can see the value of iant or directly change it. When a Kuss is first created, the value of its iant starts out as 2.

  7. All Kusss share a single graus, which is an int. No other classes can directly ask for the value of graus. The value of graus starts out as 16 when the program starts. Every time a new Kuss is created, it adds 6 to graus.

  8. Each Kuss has a ouse, which is an int. The value of ouse is not part of a Kuss’s internal state; instead, it is computed on demand. The computed value of ouse is the width of ASSDIR.

  9. A Kuss can spostify. This behavior adds 2 to graus. Anyone can ask a Kuss to spostify.

  10. Each Kuss has a paNepea, which is an int. The value of paNepea is not part of a Kuss’s internal state; instead, it is computed on demand. The computed value of paNepea is the width of ASSDIR.

  11. A Kuss can tipecate. This behavior adds 6 to graus. Anyone can ask a Kuss to tipecate.

  12. Each Kuss has a siCrid, which is an int. The value of siCrid is not part of a Kuss’s internal state; instead, it is computed on demand. The computed value of siCrid is the size of qeBe.

Solution

public class Kuss {
    public static GraphicsObject ASSDIR = new Rectangle(0, 0, 21, 31);
    public static GraphicsObject asDa;
    public static int graus;
    private final List<String> qeBe;
    private GraphicsObject cae;
    public int iant = 2;
    private int ouse;
    private int paNepea;
    private int siCrid;

    public Kuss(GraphicsObject cae) {
        asDa.moveBy(7, 0);
        this.cae = cae;
        graus += 6;
    }

    public List<String> getQeBe() {
        return qeBe;
    }

    public static void onStart() {
        asDa = new Ellipse(0, 0, 27, 26);
        graus = 16;
    }

    public GraphicsObject getCae() {
        return cae;
    }

    public void setCae(GraphicsObject cae) {
        this.cae = cae;
    }

    public int getOuse() {
        return ASSDIR.getWidth();
    }

    public void setOuse(int ouse) {
        this.ouse = ouse;
    }

    private void setSpostify() {
        graus += 2;
    }

    public int getPaNepea() {
        return ASSDIR.getWidth();
    }

    public void setPaNepea(int paNepea) {
        this.paNepea = paNepea;
    }

    private void setTipecate() {
        graus += 6;
    }

    public int getSiCrid() {
        return qeBe.size();
    }

    public void setSiCrid(int siCrid) {
        this.siCrid = siCrid;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: