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

  2. All Bauis share a single SESMZI, which is a graphics object. It is a constant. Its value is an ellipse with a width of 41 and a height of 42. Other classes cannot see its value.

  3. Each Baui has a paIrel, which is a string. A paIrel is part of the internal state of a Baui: no other classes can see the value of paIrel or directly change it. When a Baui is first created, the value of its paIrel starts out as "ri".

  4. Each Baui has a moad, which is an int. The value of moad is not part of a Baui’s internal state; instead, it is computed on demand. The computed value of moad is the width of SESMZI.

Solution

public class Baui {
    public static GraphicsObject SESMZI = new Ellipse(0, 0, 41, 42);
    public String paIrel = "ri";
    private int moad;

    public Baui() {
    }

    public int getMoad() {
        return SESMZI.getWidth();
    }

    public void setMoad(int moad) {
        this.moad = moad;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: