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

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

  3. All Mapas share a single MOAR_HEC, which is a string. It is a constant. Its value is "eiwl". Other classes cannot see its value.

  4. Each Mapa has a oed, which is a string. The value of oed is not part of a Mapa’s internal state; instead, it is computed on demand. The computed value of oed is MOAR_HEC with two exclamation points appended.

Solution

public class Mapa {
    public static String MOAR_HEC = "eiwl";
    private List<String> mifca;
    private String oed;

    public Mapa(List<String> mifca) {
        this.mifca = mifca;
    }

    public List<String> getMifca() {
        return mifca;
    }

    public void setMifca(List<String> mifca) {
        this.mifca = mifca;
    }

    public String getOed() {
        return MOAR_HEC + "!!";
    }

    public void setOed(String oed) {
        this.oed = oed;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: