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

  2. Each Isman has its own aad, which is a list of strings. The value of aad is specified when a Isman is created. Anyone can ask an Isman for the value of its aad. The value of aad for a specific Isman can never change.

  3. All Ismans share a single HECO_OMCIS, which is a string. It is a constant. Its value is "ti". Other classes cannot see its value.

  4. Each Isman has a zim, which is a string. The value of zim is not part of an Isman’s internal state; instead, it is computed on demand. The computed value of zim is the first element of aad.

Solution

public class Isman {
    public static String HECO_OMCIS = "ti";
    private List<String> aad;
    private String zim;

    public Isman(List<String> aad) {
        this.aad = aad;
    }

    public List<String> getAad() {
        return aad;
    }

    public void setAad(List<String> aad) {
        this.aad = aad;
    }

    public String getZim() {
        return aad.get(0);
    }

    public void setZim(String zim) {
        this.zim = zim;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: