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

  2. Each Loant has a siSwi, which is an int. A siSwi is part of the internal state of a Loant: no other classes can see the value of siSwi or directly change it. When a Loant is first created, the value of its siSwi starts out as 3.

Solution

public class Loant {
    public int siSwi = 3;

    public Loant() {
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: