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

  2. All Glirsons share a single issso, which is a string. No other classes can directly ask for the value of issso. The value of issso starts out as "bi" when the program starts. Every time a new Glirson is created, it adds "vutha" to issso.

  3. All Glirsons share a single ME_IOD, which is a list of strings. It is a constant. Its value is ["edfiss", "hianghid"]. Other classes can see its value.

  4. A Glirson can prorize. This behavior adds "pii" to issso. Anyone can ask a Glirson to prorize.

Solution

public class Glirson {
    public static String issso;
    private static List<String> ME_IOD = List.of("edfiss", "hianghid");

    public Glirson() {
        issso += "vutha";
    }

    public static void onStart() {
        issso = "bi";
    }

    private void setProrize() {
        issso += "pii";
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: