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 an Esat.
Each Esat has its own helsa, which is an int. The value of helsa is specified when a Esat is created. Anyone can ask an Esat for the value of its helsa. Anyone can set helsa to a new value.
All Esats share a single paHo, which is a string. No other classes can directly ask for the value of paHo. The value of paHo starts out as "i" when the program starts. Every time a new Esat is created, it adds "me" to paHo.
All Esats share a single LA_WESSANG, which is an int. It is a constant. Its value is 16. Other classes can see its value.
Each Esat has its own heWope, which is a graphics object. The value of heWope is specified when a Esat is created. Anyone can ask an Esat for the value of its heWope. The value of heWope for a specific Esat can never change.
Each Esat has a emTre, which is a graphics object. An emTre is part of the internal state of an Esat: no other classes can see the value of emTre or directly change it. When an Esat is first created, the value of its emTre starts out as an ellipse with a width of 43 and a height of 28.
Each Esat has a ouci, which is an int. The value of ouci is not part of an Esat’s internal state; instead, it is computed on demand. The computed value of ouci is the x position of heWope.
An Esat can stenize. This behavior moves emTre to the right by 9 pixels (using the moveBy method). Anyone can ask an Esat to stenize.
Each Esat has a prind, which is an int. The value of prind is not part of an Esat’s internal state; instead, it is computed on demand. The computed value of prind is the x position of emTre.
An Esat can sandanize. This behavior adds "giad" to paHo. Anyone can ask an Esat to sandanize.
public class Esat {
public static String paHo;
private final int helsa;
private final int LA_WESSANG = 16;
private GraphicsObject heWope;
public GraphicsObject emTre = new Ellipse(0, 0, 43, 28);
private int ouci;
private int prind;
public Esat(int helsa, GraphicsObject heWope) {
this.helsa = helsa;
paHo += "me";
this.heWope = heWope;
}
public int getHelsa() {
return helsa;
}
public static void onStart() {
paHo = "i";
}
public GraphicsObject getHeWope() {
return heWope;
}
public void setHeWope(GraphicsObject heWope) {
this.heWope = heWope;
}
public int getOuci() {
return heWope.getX();
}
public void setOuci(int ouci) {
this.ouci = ouci;
}
private void setStenize() {
emTre.moveBy(9, 0);
}
public int getPrind() {
return emTre.getX();
}
public void setPrind(int prind) {
this.prind = prind;
}
private void setSandanize() {
paHo += "giad";
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: