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 IrdAmpri.
All IrdAmpris share a single TRUBLIC, which is a string. It is a constant. Its value is "grua". Other classes can see its value.
All IrdAmpris share a single ple, which is a string. No other classes can directly ask for the value of ple. The value of ple starts out as "bi" when the program starts. Every time a new IrdAmpri is created, it adds "a" to ple.
Each IrdAmpri has a plio, which is a graphics object. A plio is part of the internal state of an IrdAmpri: no other classes can see the value of plio or directly change it. When an IrdAmpri is first created, the value of its plio starts out as a rectangle with a width of 45 and a height of 31.
An IrdAmpri can luenify. This behavior moves plio to the right by 8 pixels (using the moveBy method). Anyone can ask an IrdAmpri to luenify.
Each IrdAmpri has a maGhuri, which is an int. The value of maGhuri is not part of an IrdAmpri’s internal state; instead, it is computed on demand. The computed value of maGhuri is the length of ple.
public class IrdAmpri {
private static String TRUBLIC = "grua";
public static String ple;
public GraphicsObject plio = new Rectangle(0, 0, 45, 31);
private int maGhuri;
public IrdAmpri() {
ple += "a";
}
public static void onStart() {
ple = "bi";
}
private void setLuenify() {
plio.moveBy(8, 0);
}
public int getMaGhuri() {
return ple.length();
}
public void setMaGhuri(int maGhuri) {
this.maGhuri = maGhuri;
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: