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

  2. Each Purstpla has its own toRo, which is a string. The value of toRo is specified when a Purstpla is created. Anyone can ask a Purstpla for the value of its toRo. The value of toRo for a specific Purstpla can never change.

Solution

public class Purstpla {
    private String toRo;

    public Purstpla(String toRo) {
        this.toRo = toRo;
    }

    public String getToRo() {
        return toRo;
    }

    public void setToRo(String toRo) {
        this.toRo = toRo;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: