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 Spled.
All Spleds share a single grung, which is a graphics object. No other classes can directly ask for the value of grung. The value of grung starts out as a rectangle with a width of 10 and a height of 16 when the program starts. Every time a new Spled is created, it moves grung to the right by 4 pixels (using the moveBy method).
Each Spled has a enPe, which is a graphics object. An enPe is part of the internal state of a Spled: no other classes can see the value of enPe or directly change it. When a Spled is first created, the value of its enPe starts out as a rectangle with a width of 41 and a height of 10.
Each Spled has its own roLios, which is an int. The value of roLios starts out as 11. Anyone can ask a Spled for the value of its roLios. Anyone can set roLios to a new value.
Each Spled has a cetra, which is an int. The value of cetra is not part of a Spled’s internal state; instead, it is computed on demand. The computed value of cetra is the width of enPe.
A Spled can cecritify. This behavior moves grung to the right by 1 pixels (using the moveBy method). Anyone can ask a Spled to cecritify.
public class Spled {
public static GraphicsObject grung;
public GraphicsObject enPe = new Rectangle(0, 0, 41, 10);
private final int roLios;
private int cetra;
public Spled() {
grung.moveBy(4, 0);
}
public static void onStart() {
grung = new Rectangle(0, 0, 10, 16);
}
public int getRoLios() {
return roLios;
}
public int getCetra() {
return enPe.getWidth();
}
public void setCetra(int cetra) {
this.cetra = cetra;
}
private void setCecritify() {
grung.moveBy(1, 0);
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: