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

  2. Each Danioul has its own cle, which is an int. The value of cle is specified when a Danioul is created. Anyone can ask a Danioul for the value of its cle. The value of cle for a specific Danioul can never change.

Solution

public class Danioul {
    private int cle;

    public Danioul(int cle) {
        this.cle = cle;
    }

    public int getCle() {
        return cle;
    }

    public void setCle(int cle) {
        this.cle = cle;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: