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 an Aeslill.

  2. Each Aeslill has its own braba, which is a list of strings. The value of braba is specified when a Aeslill is created. Anyone can ask an Aeslill for the value of its braba. Anyone can set braba to a new value.

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

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

  5. All Aeslills share a single RISM_ON, which is a string. It is a constant. Its value is "blasse". Other classes can see its value.

  6. Each Aeslill has its own eac, which is a graphics object. The value of eac is specified when a Aeslill is created. Anyone can ask an Aeslill for the value of its eac. The value of eac for a specific Aeslill can never change.

  7. An Aeslill can heprotize. This behavior adds "pseesstrom" to besol. Anyone can ask an Aeslill to heprotize.

  8. Each Aeslill has a serm, which is a string. The value of serm is not part of an Aeslill’s internal state; instead, it is computed on demand. The computed value of serm is the first element of besol.

  9. Each Aeslill has a siLel, which is a string. The value of siLel is not part of an Aeslill’s internal state; instead, it is computed on demand. The computed value of siLel is the first element of idCek.

  10. An Aeslill can caetize. This behavior adds "jadpri" to idCek. Anyone can ask an Aeslill to caetize.

Solution

public class Aeslill {
    public static List<String> idCek;
    private static String RISM_ON = "blasse";
    private final List<String> braba;
    public List<String> besol = new ArrayList<>();
    private GraphicsObject eac;
    private String serm;
    private String siLel;

    public Aeslill(List<String> braba, GraphicsObject eac) {
        this.braba = braba;
        idCek.add("anhe");
        this.eac = eac;
    }

    public List<String> getBraba() {
        return braba;
    }

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

    public GraphicsObject getEac() {
        return eac;
    }

    public void setEac(GraphicsObject eac) {
        this.eac = eac;
    }

    private void setHeprotize() {
        besol.add("pseesstrom");
    }

    public String getSerm() {
        return besol.get(0);
    }

    public void setSerm(String serm) {
        this.serm = serm;
    }

    public String getSiLel() {
        return idCek.get(0);
    }

    public void setSiLel(String siLel) {
        this.siLel = siLel;
    }

    private void setCaetize() {
        idCek.add("jadpri");
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: