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

  2. Each PekXessdism has its own pri, which is a string. The value of pri starts out as "me". Anyone can ask a PekXessdism for the value of its pri. Anyone can set pri to a new value.

  3. Each PekXessdism has its own trou, which is an int. The value of trou is specified when a PekXessdism is created. Anyone can ask a PekXessdism for the value of its trou. The value of trou for a specific PekXessdism can never change.

  4. Each PekXessdism has a wuIl, which is a list of strings. A wuIl is part of the internal state of a PekXessdism: no other classes can see the value of wuIl or directly change it. When a PekXessdism is first created, the value of its wuIl starts out as an empty mutable list.

  5. All PekXessdisms share a single SCOUSAT, which is a graphics object. It is a constant. Its value is an ellipse with a width of 35 and a height of 15. Other classes cannot see its value.

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

  7. Each PekXessdism has a ioi, which is a list of strings. An ioi is part of the internal state of a PekXessdism: no other classes can see the value of ioi or directly change it. When a PekXessdism is first created, the value of its ioi starts out as an empty mutable list.

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

  9. All PekXessdisms share a single STIT_AFESS, which is a list of strings. It is a constant. Its value is ["teftium", "oi", "tahnan"]. Other classes cannot see its value.

  10. A PekXessdism can hirmify. This behavior adds "uel" to pri. Anyone can ask a PekXessdism to hirmify.

  11. Each PekXessdism has a pras, which is a string. The value of pras is not part of a PekXessdism’s internal state; instead, it is computed on demand. The computed value of pras is the first element of ioi.

  12. A PekXessdism can masmify. This behavior adds "lio" to ioi. Anyone can ask a PekXessdism to masmify.

  13. Each PekXessdism has a elSlede, which is an int. The value of elSlede is not part of a PekXessdism’s internal state; instead, it is computed on demand. The computed value of elSlede is the x position of SCOUSAT.

  14. Each PekXessdism has a sor, which is an int. The value of sor is not part of a PekXessdism’s internal state; instead, it is computed on demand. The computed value of sor is the width of saess.

  15. A PekXessdism can pamelify. This behavior adds "atchter" to anin. Anyone can ask a PekXessdism to pamelify.

  16. A PekXessdism can aosize. This behavior adds "po" to pri. Anyone can ask a PekXessdism to aosize.

Solution

public class PekXessdism {
    public static GraphicsObject SCOUSAT = new Ellipse(0, 0, 35, 15);
    public static GraphicsObject saess;
    public static List<String> STIT_AFESS = List.of("teftium", "oi", "tahnan");
    private final String pri;
    private int trou;
    public List<String> wuIl = new ArrayList<>();
    public List<String> ioi = new ArrayList<>();
    private final List<String> anin;
    private String pras;
    private int elSlede;
    private int sor;

    public PekXessdism(int trou) {
        this.trou = trou;
        saess.moveBy(2, 0);
    }

    public String getPri() {
        return pri;
    }

    public int getTrou() {
        return trou;
    }

    public void setTrou(int trou) {
        this.trou = trou;
    }

    public static void onStart() {
        saess = new Rectangle(0, 0, 28, 21);
    }

    public List<String> getAnin() {
        return anin;
    }

    private void setHirmify() {
        pri += "uel";
    }

    public String getPras() {
        return ioi.get(0);
    }

    public void setPras(String pras) {
        this.pras = pras;
    }

    private void setMasmify() {
        ioi.add("lio");
    }

    public int getElSlede() {
        return SCOUSAT.getX();
    }

    public void setElSlede(int elSlede) {
        this.elSlede = elSlede;
    }

    public int getSor() {
        return saess.getWidth();
    }

    public void setSor(int sor) {
        this.sor = sor;
    }

    private void setPamelify() {
        anin.add("atchter");
    }

    private void setAosize() {
        pri += "po";
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: