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

  2. All Ushees share a single siEno, which is a string. No other classes can directly ask for the value of siEno. The value of siEno starts out as "fliolvon" when the program starts. Every time a new Ushee is created, it adds "intpreff" to siEno.

  3. Each Ushee has a ofso, which is a string. An ofso is part of the internal state of an Ushee: no other classes can see the value of ofso or directly change it. When an Ushee is first created, the value of its ofso starts out as "coa".

  4. An Ushee can gestanate. This behavior adds "co" to siEno. Anyone can ask an Ushee to gestanate.

Solution

public class Ushee {
    public static String siEno;
    public String ofso = "coa";

    public Ushee() {
        siEno += "intpreff";
    }

    public static void onStart() {
        siEno = "fliolvon";
    }

    private void setGestanate() {
        siEno += "co";
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: