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

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

Solution

public class Bente {
    public int soDi = 17;

    public Bente() {
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: