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 Fodpreuth.
Each Fodpreuth has its own raPso, which is a graphics object. The value of raPso is specified when a Fodpreuth is created. Anyone can ask a Fodpreuth for the value of its raPso. The value of raPso for a specific Fodpreuth can never change.
All Fodpreuths share a single caAn, which is a graphics object. No other classes can directly ask for the value of caAn. The value of caAn starts out as a rectangle with a width of 30 and a height of 37 when the program starts. Every time a new Fodpreuth is created, it moves caAn to the right by 8 pixels (using the moveBy method).
Each Fodpreuth has its own odOrpec, which is a graphics object. The value of odOrpec starts out as an ellipse with a width of 44 and a height of 23. Anyone can ask a Fodpreuth for the value of its odOrpec. Anyone can set odOrpec to a new value.
Each Fodpreuth has a sirt, which is an int. The value of sirt is not part of a Fodpreuth’s internal state; instead, it is computed on demand. The computed value of sirt is the x position of caAn.
A Fodpreuth can rhelize. This behavior moves caAn to the right by 4 pixels (using the moveBy method). Anyone can ask a Fodpreuth to rhelize.
public class Fodpreuth {
public static GraphicsObject caAn;
private GraphicsObject raPso;
private final GraphicsObject odOrpec;
private int sirt;
public Fodpreuth(GraphicsObject raPso) {
this.raPso = raPso;
caAn.moveBy(8, 0);
}
public GraphicsObject getRaPso() {
return raPso;
}
public void setRaPso(GraphicsObject raPso) {
this.raPso = raPso;
}
public static void onStart() {
caAn = new Rectangle(0, 0, 30, 37);
}
public GraphicsObject getOdOrpec() {
return odOrpec;
}
public int getSirt() {
return caAn.getX();
}
public void setSirt(int sirt) {
this.sirt = sirt;
}
private void setRhelize() {
caAn.moveBy(4, 0);
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: