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

  2. Each Gohe has its own teic, which is an int. The value of teic starts out as 8. Anyone can ask a Gohe for the value of its teic. Anyone can set teic to a new value.

Solution

public class Gohe {
    private final int teic;

    public Gohe() {
    }

    public int getTeic() {
        return teic;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: