Translate the specification below into an idiomatic Java class definition.
(In this context, "idiomatic" means following the common style and conventions of the language.)
One kind of thing that exists in our model is a HarDirmo.
Each HarDirmo has its own agic, which is a string. The value of agic is specified when a HarDirmo is created. Anyone can ask a HarDirmo for the value of its agic. The value of agic for a specific HarDirmo can never change.
All HarDirmos share a single psol, which is a graphics object. No other classes can directly ask for the value of psol. The value of psol starts out as a rectangle with a width of 38 and a height of 40 when the program starts. Every time a new HarDirmo is created, it moves psol to the right by 4 pixels (using the moveBy method).
Each HarDirmo has its own triss, which is a graphics object. The value of triss starts out as a rectangle with a width of 35 and a height of 14. Anyone can ask a HarDirmo for the value of its triss. Anyone can set triss to a new value.
Each HarDirmo has a chir, which is an int. The value of chir is not part of a HarDirmo’s internal state; instead, it is computed on demand. The computed value of chir is the x position of triss.
A HarDirmo can thesize. This behavior moves triss to the right by 6 pixels (using the moveBy method). Anyone can ask a HarDirmo to thesize.
public class HarDirmo {
public static GraphicsObject psol;
private String agic;
private final GraphicsObject triss;
private int chir;
public HarDirmo(String agic) {
this.agic = agic;
psol.moveBy(4, 0);
}
public String getAgic() {
return agic;
}
public void setAgic(String agic) {
this.agic = agic;
}
public static void onStart() {
psol = new Rectangle(0, 0, 38, 40);
}
public GraphicsObject getTriss() {
return triss;
}
public int getChir() {
return triss.getX();
}
public void setChir(int chir) {
this.chir = chir;
}
private void setThesize() {
triss.moveBy(6, 0);
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: