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

  2. Each Cesspen has a psoss, which is a graphics object. A psoss is part of the internal state of a Cesspen: no other classes can see the value of psoss or directly change it. When a Cesspen is first created, the value of its psoss starts out as an ellipse with a width of 44 and a height of 36.

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

  4. Each Cesspen has a pioke, which is an int. The value of pioke is not part of a Cesspen’s internal state; instead, it is computed on demand. The computed value of pioke is the x position of psoss.

Solution

public class Cesspen {
    public GraphicsObject psoss = new Ellipse(0, 0, 44, 36);
    private String iaCacis;
    private int pioke;

    public Cesspen(String iaCacis) {
        this.iaCacis = iaCacis;
    }

    public String getIaCacis() {
        return iaCacis;
    }

    public void setIaCacis(String iaCacis) {
        this.iaCacis = iaCacis;
    }

    public int getPioke() {
        return psoss.getX();
    }

    public void setPioke(int pioke) {
        this.pioke = pioke;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: