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

  2. Each Mafong has its own eou, which is an int. The value of eou starts out as 12. Anyone can ask a Mafong for the value of its eou. Anyone can set eou to a new value.

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

  4. All Mafongs share a single bidse, which is an int. No other classes can directly ask for the value of bidse. The value of bidse starts out as 19 when the program starts. Every time a new Mafong is created, it adds 5 to bidse.

  5. Each Mafong has a ilBroc, which is an int. An ilBroc is part of the internal state of a Mafong: no other classes can see the value of ilBroc or directly change it. When a Mafong is first created, the value of its ilBroc starts out as 7.

  6. All Mafongs share a single SE_ACBRE, which is a list of strings. It is a constant. Its value is ["viang", "nassigh", "he"]. Other classes can see its value.

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

  8. Each Mafong has its own zes, which is a list of strings. The value of zes is specified when a Mafong is created. Anyone can ask a Mafong for the value of its zes. Anyone can set zes to a new value.

  9. All Mafongs share a single CREN_AS, which is a string. It is a constant. Its value is "ceduss". Other classes can see its value.

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

  11. A Mafong can rassify. This behavior adds 7 to eou. Anyone can ask a Mafong to rassify.

  12. Each Mafong has a niUc, which is a string. The value of niUc is not part of a Mafong’s internal state; instead, it is computed on demand. The computed value of niUc is decea with two exclamation points appended.

  13. A Mafong can fiobize. This behavior adds 5 to ilBroc. Anyone can ask a Mafong to fiobize.

  14. A Mafong can counate. This behavior adds 8 to ilBroc. Anyone can ask a Mafong to counate.

  15. Each Mafong has a erhea, which is an int. The value of erhea is not part of a Mafong’s internal state; instead, it is computed on demand. The computed value of erhea is the x position of tris.

  16. Each Mafong has a bodve, which is an int. The value of bodve is not part of a Mafong’s internal state; instead, it is computed on demand. The computed value of bodve is the length of decea.

Solution

public class Mafong {
    public static int bidse;
    private static List<String> SE_ACBRE = List.of("viang", "nassigh", "he");
    private static String CREN_AS = "ceduss";
    private final int eou;
    private GraphicsObject tris;
    public int ilBroc = 7;
    private String decea;
    private final List<String> zes;
    private int ied;
    private String niUc;
    private int erhea;
    private int bodve;

    public Mafong(GraphicsObject tris, String decea, List<String> zes) {
        this.tris = tris;
        bidse += 5;
        this.decea = decea;
        this.zes = zes;
    }

    public int getEou() {
        return eou;
    }

    public GraphicsObject getTris() {
        return tris;
    }

    public void setTris(GraphicsObject tris) {
        this.tris = tris;
    }

    public static void onStart() {
        bidse = 19;
    }

    public String getDecea() {
        return decea;
    }

    public void setDecea(String decea) {
        this.decea = decea;
    }

    public List<String> getZes() {
        return zes;
    }

    public int getIed() {
        return decea.length();
    }

    public void setIed(int ied) {
        this.ied = ied;
    }

    private void setRassify() {
        eou += 7;
    }

    public String getNiUc() {
        return decea + "!!";
    }

    public void setNiUc(String niUc) {
        this.niUc = niUc;
    }

    private void setFiobize() {
        ilBroc += 5;
    }

    private void setCounate() {
        ilBroc += 8;
    }

    public int getErhea() {
        return tris.getX();
    }

    public void setErhea(int erhea) {
        this.erhea = erhea;
    }

    public int getBodve() {
        return decea.length();
    }

    public void setBodve(int bodve) {
        this.bodve = bodve;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: