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

  2. Each Procpod has a ath, which is a graphics object. An ath is part of the internal state of a Procpod: no other classes can see the value of ath or directly change it. When a Procpod is first created, the value of its ath starts out as a rectangle with a width of 25 and a height of 28.

  3. Each Procpod has its own diiou, which is a graphics object. The value of diiou starts out as an ellipse with a width of 29 and a height of 32. Anyone can ask a Procpod for the value of its diiou. Anyone can set diiou to a new value.

  4. All Procpods share a single vea, which is a string. No other classes can directly ask for the value of vea. The value of vea starts out as "iss" when the program starts. Every time a new Procpod is created, it adds "rhoss" to vea.

  5. All Procpods share a single PRUN_ERSHAD, which is an int. It is a constant. Its value is 6. Other classes can see its value.

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

  7. Each Procpod has a urser, which is an int. The value of urser is not part of a Procpod’s internal state; instead, it is computed on demand. The computed value of urser is the x position of diiou.

  8. A Procpod can ladadify. This behavior adds "roohea" to vea. Anyone can ask a Procpod to ladadify.

  9. A Procpod can ironate. This behavior adds "treco" to vea. Anyone can ask a Procpod to ironate.

  10. Each Procpod has a scre, which is an int. The value of scre is not part of a Procpod’s internal state; instead, it is computed on demand. The computed value of scre is the length of soio.

Solution

public class Procpod {
    public static String vea;
    public GraphicsObject ath = new Rectangle(0, 0, 25, 28);
    private final GraphicsObject diiou;
    private final int PRUN_ERSHAD = 6;
    private String soio;
    private int urser;
    private int scre;

    public Procpod(String soio) {
        vea += "rhoss";
        this.soio = soio;
    }

    public GraphicsObject getDiiou() {
        return diiou;
    }

    public static void onStart() {
        vea = "iss";
    }

    public String getSoio() {
        return soio;
    }

    public void setSoio(String soio) {
        this.soio = soio;
    }

    public int getUrser() {
        return diiou.getX();
    }

    public void setUrser(int urser) {
        this.urser = urser;
    }

    private void setLadadify() {
        vea += "roohea";
    }

    private void setIronate() {
        vea += "treco";
    }

    public int getScre() {
        return soio.length();
    }

    public void setScre(int scre) {
        this.scre = scre;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: