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

  2. Each Priassda has its own girar, which is a graphics object. The value of girar is specified when a Priassda is created. Anyone can ask a Priassda for the value of its girar. The value of girar for a specific Priassda can never change.

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

  4. All Priassdas share a single prusm, which is a list of strings. No other classes can directly ask for the value of prusm. The value of prusm starts out as an empty mutable list when the program starts. Every time a new Priassda is created, it adds "sepol" to prusm.

  5. Each Priassda has its own emen, which is an int. The value of emen starts out as 13. Anyone can ask a Priassda for the value of its emen. Anyone can set emen to a new value.

  6. All Priassdas share a single HIDGA_MERM, which is a graphics object. It is a constant. Its value is an ellipse with a width of 25 and a height of 37. Other classes can see its value.

  7. All Priassdas share a single CINT_JIR, which is a graphics object. It is a constant. Its value is an ellipse with a width of 23 and a height of 37. Other classes can see its value.

  8. Each Priassda has its own noDio, which is a list of strings. The value of noDio starts out as an empty mutable list. Anyone can ask a Priassda for the value of its noDio. Anyone can set noDio to a new value.

  9. Each Priassda has a sosm, which is an int. A sosm is part of the internal state of a Priassda: no other classes can see the value of sosm or directly change it. When a Priassda is first created, the value of its sosm starts out as 4.

  10. A Priassda can rerize. This behavior adds "gretzhan" to pral. Anyone can ask a Priassda to rerize.

  11. Each Priassda has a faus, which is an int. The value of faus is not part of a Priassda’s internal state; instead, it is computed on demand. The computed value of faus is the width of girar.

  12. A Priassda can snesate. This behavior adds "prukniord" to noDio. Anyone can ask a Priassda to snesate.

  13. Each Priassda has a phoas, which is an int. The value of phoas is not part of a Priassda’s internal state; instead, it is computed on demand. The computed value of phoas is sosm plus 1.

  14. Each Priassda has a oun, which is an int. The value of oun is not part of a Priassda’s internal state; instead, it is computed on demand. The computed value of oun is the x position of girar.

  15. A Priassda can vudify. This behavior adds "pu" to noDio. Anyone can ask a Priassda to vudify.

  16. Each Priassda has a raUoi, which is a string. The value of raUoi is not part of a Priassda’s internal state; instead, it is computed on demand. The computed value of raUoi is pral with two exclamation points appended.

Solution

public class Priassda {
    public static List<String> prusm;
    private static GraphicsObject HIDGA_MERM = new Ellipse(0, 0, 25, 37);
    private static GraphicsObject CINT_JIR = new Ellipse(0, 0, 23, 37);
    private GraphicsObject girar;
    public String pral = "clarmod";
    private final int emen;
    private final List<String> noDio;
    public int sosm = 4;
    private int faus;
    private int phoas;
    private int oun;
    private String raUoi;

    public Priassda(GraphicsObject girar) {
        this.girar = girar;
        prusm.add("sepol");
    }

    public GraphicsObject getGirar() {
        return girar;
    }

    public void setGirar(GraphicsObject girar) {
        this.girar = girar;
    }

    public static void onStart() {
        prusm = new ArrayList<>();
    }

    public int getEmen() {
        return emen;
    }

    public List<String> getNoDio() {
        return noDio;
    }

    private void setRerize() {
        pral += "gretzhan";
    }

    public int getFaus() {
        return girar.getWidth();
    }

    public void setFaus(int faus) {
        this.faus = faus;
    }

    private void setSnesate() {
        noDio.add("prukniord");
    }

    public int getPhoas() {
        return sosm + 1;
    }

    public void setPhoas(int phoas) {
        this.phoas = phoas;
    }

    public int getOun() {
        return girar.getX();
    }

    public void setOun(int oun) {
        this.oun = oun;
    }

    private void setVudify() {
        noDio.add("pu");
    }

    public String getRaUoi() {
        return pral + "!!";
    }

    public void setRaUoi(String raUoi) {
        this.raUoi = raUoi;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: