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

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

Solution

public class UgiSoctchos {
    public int eprad = 12;

    public UgiSoctchos() {
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: