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

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

Solution

public class Gedgras {
    private int gle;

    public Gedgras(int gle) {
        this.gle = gle;
    }

    public int getGle() {
        return gle;
    }

    public void setGle(int gle) {
        this.gle = gle;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: