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 Tispel.
Each Tispel has its own soDerce, which is a graphics object. The value of soDerce is specified when a Tispel is created. Anyone can ask a Tispel for the value of its soDerce. The value of soDerce for a specific Tispel can never change.
Each Tispel has a daxe, which is a graphics object. A daxe is part of the internal state of a Tispel: no other classes can see the value of daxe or directly change it. When a Tispel is first created, the value of its daxe starts out as a rectangle with a width of 43 and a height of 19.
All Tispels share a single DENSTU, which is a graphics object. It is a constant. Its value is an ellipse with a width of 21 and a height of 32. Other classes cannot see its value.
A Tispel can clirize. This behavior moves daxe to the right by 2 pixels (using the moveBy method). Anyone can ask a Tispel to clirize.
Each Tispel has a surne, which is an int. The value of surne is not part of a Tispel’s internal state; instead, it is computed on demand. The computed value of surne is the x position of soDerce.
public class Tispel {
public static GraphicsObject DENSTU = new Ellipse(0, 0, 21, 32);
private GraphicsObject soDerce;
public GraphicsObject daxe = new Rectangle(0, 0, 43, 19);
private int surne;
public Tispel(GraphicsObject soDerce) {
this.soDerce = soDerce;
}
public GraphicsObject getSoDerce() {
return soDerce;
}
public void setSoDerce(GraphicsObject soDerce) {
this.soDerce = soDerce;
}
private void setClirize() {
daxe.moveBy(2, 0);
}
public int getSurne() {
return soDerce.getX();
}
public void setSurne(int surne) {
this.surne = surne;
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: