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

  2. All Pruds share a single OSUST_SALLMIM, which is a graphics object. It is a constant. Its value is an ellipse with a width of 21 and a height of 44. Other classes can see its value.

  3. Each Prud has its own aghur, which is an int. The value of aghur starts out as 16. Anyone can ask a Prud for the value of its aghur. Anyone can set aghur to a new value.

  4. All Pruds share a single ces, which is a string. No other classes can directly ask for the value of ces. The value of ces starts out as "pa" when the program starts. Every time a new Prud is created, it adds "tulqen" to ces.

  5. Each Prud has its own oprac, which is a string. The value of oprac is specified when a Prud is created. Anyone can ask a Prud for the value of its oprac. The value of oprac for a specific Prud can never change.

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

  7. Each Prud has its own ilAl, which is an int. The value of ilAl starts out as 17. Anyone can ask a Prud for the value of its ilAl. Anyone can set ilAl to a new value.

  8. All Pruds share a single fuet, which is a list of strings. No other classes can directly ask for the value of fuet. The value of fuet starts out as an empty mutable list when the program starts. Every time a new Prud is created, it adds "pluhi" to fuet.

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

  10. A Prud can lalate. This behavior adds 7 to aghur. Anyone can ask a Prud to lalate.

  11. Each Prud has a taeo, which is a string. The value of taeo is not part of a Prud’s internal state; instead, it is computed on demand. The computed value of taeo is ces with two exclamation points appended.

  12. A Prud can usmfelify. This behavior adds "er" to coPempu. Anyone can ask a Prud to usmfelify.

  13. Each Prud has a zus, which is an int. The value of zus is not part of a Prud’s internal state; instead, it is computed on demand. The computed value of zus is ilAl squared.

  14. A Prud can ohiphate. This behavior adds "tevis" to fuet. Anyone can ask a Prud to ohiphate.

  15. Each Prud has a foWasan, which is a string. The value of foWasan is not part of a Prud’s internal state; instead, it is computed on demand. The computed value of foWasan is the first element of fuet.

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

Solution

public class Prud {
    private static GraphicsObject OSUST_SALLMIM = new Ellipse(0, 0, 21, 44);
    public static String ces;
    public static List<String> fuet;
    private final int aghur;
    private String oprac;
    public String coPempu = "siel";
    private final int ilAl;
    private List<String> ijoar;
    private String taeo;
    private int zus;
    private String foWasan;
    private int oiwgo;

    public Prud(String oprac, List<String> ijoar) {
        ces += "tulqen";
        this.oprac = oprac;
        fuet.add("pluhi");
        this.ijoar = ijoar;
    }

    public int getAghur() {
        return aghur;
    }

    public static void onStart() {
        ces = "pa";
        fuet = new ArrayList<>();
    }

    public String getOprac() {
        return oprac;
    }

    public void setOprac(String oprac) {
        this.oprac = oprac;
    }

    public int getIlAl() {
        return ilAl;
    }

    public List<String> getIjoar() {
        return ijoar;
    }

    public void setIjoar(List<String> ijoar) {
        this.ijoar = ijoar;
    }

    private void setLalate() {
        aghur += 7;
    }

    public String getTaeo() {
        return ces + "!!";
    }

    public void setTaeo(String taeo) {
        this.taeo = taeo;
    }

    private void setUsmfelify() {
        coPempu += "er";
    }

    public int getZus() {
        return ilAl * ilAl;
    }

    public void setZus(int zus) {
        this.zus = zus;
    }

    private void setOhiphate() {
        fuet.add("tevis");
    }

    public String getFoWasan() {
        return fuet.get(0);
    }

    public void setFoWasan(String foWasan) {
        this.foWasan = foWasan;
    }

    public int getOiwgo() {
        return fuet.size();
    }

    public void setOiwgo(int oiwgo) {
        this.oiwgo = oiwgo;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: