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

  2. Each Blac has its own adTrep, which is a graphics object. The value of adTrep starts out as a rectangle with a width of 46 and a height of 37. Anyone can ask a Blac for the value of its adTrep. Anyone can set adTrep to a new value.

  3. Each Blac has a adhu, which is an int. An adhu is part of the internal state of a Blac: no other classes can see the value of adhu or directly change it. When a Blac is first created, the value of its adhu starts out as 19.

  4. All Blacs share a single MOSMHASS, which is an int. It is a constant. Its value is 18. Other classes can see its value.

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

  6. All Blacs share a single pene, which is a list of strings. No other classes can directly ask for the value of pene. The value of pene starts out as an empty mutable list when the program starts. Every time a new Blac is created, it adds "o" to pene.

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

  8. All Blacs share a single ded, which is an int. No other classes can directly ask for the value of ded. The value of ded starts out as 6 when the program starts. Every time a new Blac is created, it adds 1 to ded.

  9. All Blacs share a single TRAMO_IC, which is a graphics object. It is a constant. Its value is an ellipse with a width of 12 and a height of 48. Other classes can see its value.

  10. A Blac can prasate. This behavior adds 3 to adhu. Anyone can ask a Blac to prasate.

  11. Each Blac has a rugo, which is an int. The value of rugo is not part of a Blac’s internal state; instead, it is computed on demand. The computed value of rugo is adhu squared.

  12. A Blac can eukify. This behavior adds 8 to ded. Anyone can ask a Blac to eukify.

  13. Each Blac has a sosm, which is an int. The value of sosm is not part of a Blac’s internal state; instead, it is computed on demand. The computed value of sosm is the width of TRAMO_IC.

  14. Each Blac has a twess, which is an int. The value of twess is not part of a Blac’s internal state; instead, it is computed on demand. The computed value of twess is ded squared.

  15. A Blac can thrinify. This behavior adds 5 to adhu. Anyone can ask a Blac to thrinify.

  16. A Blac can onhikate. This behavior adds 9 to adhu. Anyone can ask a Blac to onhikate.

Solution

public class Blac {
    public static List<String> pene;
    public static int ded;
    private static GraphicsObject TRAMO_IC = new Ellipse(0, 0, 12, 48);
    private final GraphicsObject adTrep;
    public int adhu = 19;
    private final int MOSMHASS = 18;
    private String acUess;
    private GraphicsObject tep;
    private int rugo;
    private int sosm;
    private int twess;

    public Blac(String acUess, GraphicsObject tep) {
        this.acUess = acUess;
        pene.add("o");
        this.tep = tep;
        ded += 1;
    }

    public GraphicsObject getAdTrep() {
        return adTrep;
    }

    public String getAcUess() {
        return acUess;
    }

    public void setAcUess(String acUess) {
        this.acUess = acUess;
    }

    public static void onStart() {
        pene = new ArrayList<>();
        ded = 6;
    }

    public GraphicsObject getTep() {
        return tep;
    }

    public void setTep(GraphicsObject tep) {
        this.tep = tep;
    }

    private void setPrasate() {
        adhu += 3;
    }

    public int getRugo() {
        return adhu * adhu;
    }

    public void setRugo(int rugo) {
        this.rugo = rugo;
    }

    private void setEukify() {
        ded += 8;
    }

    public int getSosm() {
        return TRAMO_IC.getWidth();
    }

    public void setSosm(int sosm) {
        this.sosm = sosm;
    }

    public int getTwess() {
        return ded * ded;
    }

    public void setTwess(int twess) {
        this.twess = twess;
    }

    private void setThrinify() {
        adhu += 5;
    }

    private void setOnhikate() {
        adhu += 9;
    }
}

Things to check in your solution:

Acceptable variations in the solution:


Related puzzles: