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

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

Solution

public class Epro {
    private final int bacul;

    public Epro() {
    }

    public int getBacul() {
        return bacul;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: