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

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

  3. All HulIonsengs share a single ceng, which is a list of strings. No other classes can directly ask for the value of ceng. The value of ceng starts out as an empty mutable list when the program starts. Every time a new HulIonseng is created, it adds "ang" to ceng.

  4. All HulIonsengs share a single LITDI_TRILCREM, which is an int. It is a constant. Its value is 18. Other classes can see its value.

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

  6. Each HulIonseng has its own reu, which is an int. The value of reu starts out as 10. Anyone can ask a HulIonseng for the value of its reu. Anyone can set reu to a new value.

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

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

  9. Each HulIonseng has a smoun, which is an int. The value of smoun is not part of a HulIonseng’s internal state; instead, it is computed on demand. The computed value of smoun is the size of ceng.

  10. A HulIonseng can scatize. This behavior adds "sordan" to gec. Anyone can ask a HulIonseng to scatize.

  11. Each HulIonseng has a ilTi, which is an int. The value of ilTi is not part of a HulIonseng’s internal state; instead, it is computed on demand. The computed value of ilTi is the length of qasec.

  12. A HulIonseng can elmonate. This behavior adds "pezci" to qasec. Anyone can ask a HulIonseng to elmonate.

  13. A HulIonseng can irdbolate. This behavior adds "i" to qasec. Anyone can ask a HulIonseng to irdbolate.

  14. Each HulIonseng has a ipCed, which is an int. The value of ipCed is not part of a HulIonseng’s internal state; instead, it is computed on demand. The computed value of ipCed is the length of qasec.

Solution

public class HulIonseng {
    public static List<String> ceng;
    private GraphicsObject miBe;
    private final int LITDI_TRILCREM = 18;
    public String qasec = "safir";
    private final int reu;
    private final List<String> gec;
    private List<String> daMisu;
    private int smoun;
    private int ilTi;
    private int ipCed;

    public HulIonseng(GraphicsObject miBe, List<String> daMisu) {
        this.miBe = miBe;
        ceng.add("ang");
        this.daMisu = daMisu;
    }

    public GraphicsObject getMiBe() {
        return miBe;
    }

    public void setMiBe(GraphicsObject miBe) {
        this.miBe = miBe;
    }

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

    public int getReu() {
        return reu;
    }

    public List<String> getGec() {
        return gec;
    }

    public List<String> getDaMisu() {
        return daMisu;
    }

    public void setDaMisu(List<String> daMisu) {
        this.daMisu = daMisu;
    }

    public int getSmoun() {
        return ceng.size();
    }

    public void setSmoun(int smoun) {
        this.smoun = smoun;
    }

    private void setScatize() {
        gec.add("sordan");
    }

    public int getIlTi() {
        return qasec.length();
    }

    public void setIlTi(int ilTi) {
        this.ilTi = ilTi;
    }

    private void setElmonate() {
        qasec += "pezci";
    }

    private void setIrdbolate() {
        qasec += "i";
    }

    public int getIpCed() {
        return qasec.length();
    }

    public void setIpCed(int ipCed) {
        this.ipCed = ipCed;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: