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 Cada.
All Cadas share a single haDu, which is a string. No other classes can directly ask for the value of haDu. The value of haDu starts out as "cabpi" when the program starts. Every time a new Cada is created, it adds "mec" to haDu.
All Cadas share a single BILDI_BEEPODD, which is a graphics object. It is a constant. Its value is a rectangle with a width of 45 and a height of 36. Other classes can see its value.
Each Cada has a emSles, which is an int. The value of emSles is not part of a Cada’s internal state; instead, it is computed on demand. The computed value of emSles is the x position of BILDI_BEEPODD.
public class Cada {
public static String haDu;
private static GraphicsObject BILDI_BEEPODD = new Rectangle(0, 0, 45, 36);
private int emSles;
public Cada() {
haDu += "mec";
}
public static void onStart() {
haDu = "cabpi";
}
public int getEmSles() {
return BILDI_BEEPODD.getX();
}
public void setEmSles(int emSles) {
this.emSles = emSles;
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: