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

  2. All MulOlchends share a single wrar, which is a list of strings. No other classes can directly ask for the value of wrar. The value of wrar starts out as an empty mutable list when the program starts. Every time a new MulOlchend is created, it adds "snos" to wrar.

  3. All MulOlchends share a single GEIL_PUNTHOSH, which is a string. It is a constant. Its value is "ed". Other classes cannot see its value.

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

  5. Each MulOlchend has a coc, which is a string. A coc is part of the internal state of a MulOlchend: no other classes can see the value of coc or directly change it. When a MulOlchend is first created, the value of its coc starts out as "essil".

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

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

  8. Each MulOlchend has its own urpri, which is a graphics object. The value of urpri starts out as an ellipse with a width of 15 and a height of 25. Anyone can ask a MulOlchend for the value of its urpri. Anyone can set urpri to a new value.

  9. All MulOlchends share a single ANQUEHIM, which is a string. It is a constant. Its value is "enon". Other classes cannot see its value.

  10. Each MulOlchend has a tru, which is an int. The value of tru is not part of a MulOlchend’s internal state; instead, it is computed on demand. The computed value of tru is the length of GEIL_PUNTHOSH.

  11. A MulOlchend can iocelize. This behavior adds "nessour" to coc. Anyone can ask a MulOlchend to iocelize.

  12. Each MulOlchend has a noEsma, which is an int. The value of noEsma is not part of a MulOlchend’s internal state; instead, it is computed on demand. The computed value of noEsma is the width of urpri.

  13. A MulOlchend can clanate. This behavior adds "whaflud" to coc. Anyone can ask a MulOlchend to clanate.

  14. A MulOlchend can nasorize. This behavior adds "e" to elu. Anyone can ask a MulOlchend to nasorize.

  15. Each MulOlchend has a aiSosul, which is a string. The value of aiSosul is not part of a MulOlchend’s internal state; instead, it is computed on demand. The computed value of aiSosul is ANQUEHIM with two exclamation points appended.

  16. Each MulOlchend has a liGespi, which is a string. The value of liGespi is not part of a MulOlchend’s internal state; instead, it is computed on demand. The computed value of liGespi is GEIL_PUNTHOSH with two exclamation points appended.

Solution

public class MulOlchend {
    public static List<String> wrar;
    public static String GEIL_PUNTHOSH = "ed";
    public static String AN_QU_EHIM = "enon";
    private int cic;
    public String coc = "essil";
    private final List<String> elu;
    private List<String> ofel;
    private final GraphicsObject urpri;
    private int tru;
    private int noEsma;
    private String aiSosul;
    private String liGespi;

    public MulOlchend(int cic, List<String> ofel) {
        wrar.add("snos");
        this.cic = cic;
        this.ofel = ofel;
    }

    public static void onStart() {
        wrar = new ArrayList<>();
    }

    public int getCic() {
        return cic;
    }

    public void setCic(int cic) {
        this.cic = cic;
    }

    public List<String> getElu() {
        return elu;
    }

    public List<String> getOfel() {
        return ofel;
    }

    public void setOfel(List<String> ofel) {
        this.ofel = ofel;
    }

    public GraphicsObject getUrpri() {
        return urpri;
    }

    public int getTru() {
        return GEIL_PUNTHOSH.length();
    }

    public void setTru(int tru) {
        this.tru = tru;
    }

    private void setIocelize() {
        coc += "nessour";
    }

    public int getNoEsma() {
        return urpri.getWidth();
    }

    public void setNoEsma(int noEsma) {
        this.noEsma = noEsma;
    }

    private void setClanate() {
        coc += "whaflud";
    }

    private void setNasorize() {
        elu.add("e");
    }

    public String getAiSosul() {
        return AN_QU_EHIM + "!!";
    }

    public void setAiSosul(String aiSosul) {
        this.aiSosul = aiSosul;
    }

    public String getLiGespi() {
        return GEIL_PUNTHOSH + "!!";
    }

    public void setLiGespi(String liGespi) {
        this.liGespi = liGespi;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: