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

  2. Each Fior has a wiOfed, which is a list of strings. A wiOfed is part of the internal state of a Fior: no other classes can see the value of wiOfed or directly change it. When a Fior is first created, the value of its wiOfed starts out as an empty mutable list.

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

  4. All Fiors share a single HIRAD_BROCE, which is a list of strings. It is a constant. Its value is ["lantro", "to"]. Other classes cannot see its value.

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

  6. All Fiors share a single elIias, which is a string. No other classes can directly ask for the value of elIias. The value of elIias starts out as "sclihi" when the program starts. Every time a new Fior is created, it adds "testac" to elIias.

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

  8. All Fiors share a single PECOSS, which is a graphics object. It is a constant. Its value is an ellipse with a width of 41 and a height of 45. Other classes can see its value.

  9. Each Fior has a atNa, which is a graphics object. An atNa is part of the internal state of a Fior: no other classes can see the value of atNa or directly change it. When a Fior is first created, the value of its atNa starts out as an ellipse with a width of 29 and a height of 19.

  10. A Fior can phengify. This behavior adds "ar" to wiOfed. Anyone can ask a Fior to phengify.

  11. Each Fior has a ibTe, which is a string. The value of ibTe is not part of a Fior’s internal state; instead, it is computed on demand. The computed value of ibTe is the first element of HIRAD_BROCE.

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

  13. A Fior can ostate. This behavior adds "scua" to elIias. Anyone can ask a Fior to ostate.

  14. A Fior can maerate. This behavior moves atNa to the right by 1 pixels (using the moveBy method). Anyone can ask a Fior to maerate.

  15. Each Fior has a idard, which is an int. The value of idard is not part of a Fior’s internal state; instead, it is computed on demand. The computed value of idard is the size of wiOfed.

  16. Each Fior has a seRi, which is an int. The value of seRi is not part of a Fior’s internal state; instead, it is computed on demand. The computed value of seRi is the width of atNa.

Solution

public class Fior {
    public static List<String> HIRAD_BROCE = List.of("lantro", "to");
    public static String elIias;
    private static GraphicsObject PECOSS = new Ellipse(0, 0, 41, 45);
    public List<String> wiOfed = new ArrayList<>();
    private int skea;
    private final List<String> hese;
    private GraphicsObject epres;
    public GraphicsObject atNa = new Ellipse(0, 0, 29, 19);
    private String ibTe;
    private String feKecku;
    private int idard;
    private int seRi;

    public Fior(int skea, GraphicsObject epres) {
        this.skea = skea;
        elIias += "testac";
        this.epres = epres;
    }

    public int getSkea() {
        return skea;
    }

    public void setSkea(int skea) {
        this.skea = skea;
    }

    public List<String> getHese() {
        return hese;
    }

    public static void onStart() {
        elIias = "sclihi";
    }

    public GraphicsObject getEpres() {
        return epres;
    }

    public void setEpres(GraphicsObject epres) {
        this.epres = epres;
    }

    private void setPhengify() {
        wiOfed.add("ar");
    }

    public String getIbTe() {
        return HIRAD_BROCE.get(0);
    }

    public void setIbTe(String ibTe) {
        this.ibTe = ibTe;
    }

    public String getFeKecku() {
        return elIias + "!!";
    }

    public void setFeKecku(String feKecku) {
        this.feKecku = feKecku;
    }

    private void setOstate() {
        elIias += "scua";
    }

    private void setMaerate() {
        atNa.moveBy(1, 0);
    }

    public int getIdard() {
        return wiOfed.size();
    }

    public void setIdard(int idard) {
        this.idard = idard;
    }

    public int getSeRi() {
        return atNa.getWidth();
    }

    public void setSeRi(int seRi) {
        this.seRi = seRi;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: