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

  2. Each Timod has a oinor, which is a string. An oinor is part of the internal state of a Timod: no other classes can see the value of oinor or directly change it. When a Timod is first created, the value of its oinor starts out as "qe".

  3. Each Timod has its own weou, which is a graphics object. The value of weou starts out as an ellipse with a width of 47 and a height of 17. Anyone can ask a Timod for the value of its weou. Anyone can set weou to a new value.

  4. All Timods share a single lil, which is an int. No other classes can directly ask for the value of lil. The value of lil starts out as 12 when the program starts. Every time a new Timod is created, it adds 7 to lil.

  5. All Timods share a single CHOFRI, which is a list of strings. It is a constant. Its value is ["pe", "ditsen", "arbar"]. Other classes cannot see its value.

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

  7. All Timods share a single tiash, which is a list of strings. No other classes can directly ask for the value of tiash. The value of tiash starts out as an empty mutable list when the program starts. Every time a new Timod is created, it adds "riom" to tiash.

  8. Each Timod has its own cuoss, which is a string. The value of cuoss is specified when a Timod is created. Anyone can ask a Timod for the value of its cuoss. Anyone can set cuoss to a new value.

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

  10. Each Timod has a zusm, which is an int. The value of zusm is not part of a Timod’s internal state; instead, it is computed on demand. The computed value of zusm is lil squared.

  11. A Timod can scelize. This behavior adds "padhuoss" to tiash. Anyone can ask a Timod to scelize.

  12. Each Timod has a uss, which is an int. The value of uss is not part of a Timod’s internal state; instead, it is computed on demand. The computed value of uss is lil squared.

  13. A Timod can uismelize. This behavior adds "wreac" to oinor. Anyone can ask a Timod to uismelize.

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

  15. A Timod can armonize. This behavior adds "iestsi" to cui. Anyone can ask a Timod to armonize.

  16. Each Timod has a tre, which is an int. The value of tre is not part of a Timod’s internal state; instead, it is computed on demand. The computed value of tre is the size of tiash.

Solution

public class Timod {
    public static int lil;
    public static List<String> CHOFRI = List.of("pe", "ditsen", "arbar");
    public static List<String> tiash;
    public String oinor = "qe";
    private final GraphicsObject weou;
    private int aon;
    private final String cuoss;
    public String cui = "ri";
    private int zusm;
    private int uss;
    private int kaso;
    private int tre;

    public Timod(int aon, String cuoss) {
        lil += 7;
        this.aon = aon;
        tiash.add("riom");
        this.cuoss = cuoss;
    }

    public GraphicsObject getWeou() {
        return weou;
    }

    public static void onStart() {
        lil = 12;
        tiash = new ArrayList<>();
    }

    public int getAon() {
        return aon;
    }

    public void setAon(int aon) {
        this.aon = aon;
    }

    public String getCuoss() {
        return cuoss;
    }

    public int getZusm() {
        return lil * lil;
    }

    public void setZusm(int zusm) {
        this.zusm = zusm;
    }

    private void setScelize() {
        tiash.add("padhuoss");
    }

    public int getUss() {
        return lil * lil;
    }

    public void setUss(int uss) {
        this.uss = uss;
    }

    private void setUismelize() {
        oinor += "wreac";
    }

    public int getKaso() {
        return cuoss.length();
    }

    public void setKaso(int kaso) {
        this.kaso = kaso;
    }

    private void setArmonize() {
        cui += "iestsi";
    }

    public int getTre() {
        return tiash.size();
    }

    public void setTre(int tre) {
        this.tre = tre;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: