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 Pilshin.
All Pilshins share a single LEERHAL, which is a string. It is a constant. Its value is "sperpe". Other classes can see its value.
Each Pilshin has its own mados, which is an int. The value of mados starts out as 18. Anyone can ask a Pilshin for the value of its mados. Anyone can set mados to a new value.
All Pilshins share a single diCloss, which is a list of strings. No other classes can directly ask for the value of diCloss. The value of diCloss starts out as an empty mutable list when the program starts. Every time a new Pilshin is created, it adds "perdren" to diCloss.
Each Pilshin has its own nen, which is an int. The value of nen is specified when a Pilshin is created. Anyone can ask a Pilshin for the value of its nen. The value of nen for a specific Pilshin can never change.
Each Pilshin has a doar, which is a list of strings. A doar is part of the internal state of a Pilshin: no other classes can see the value of doar or directly change it. When a Pilshin is first created, the value of its doar starts out as an empty mutable list.
All Pilshins share a single swir, which is an int. No other classes can directly ask for the value of swir. The value of swir starts out as 1 when the program starts. Every time a new Pilshin is created, it adds 5 to swir.
Each Pilshin has its own oght, which is a graphics object. The value of oght starts out as a rectangle with a width of 37 and a height of 28. Anyone can ask a Pilshin for the value of its oght. Anyone can set oght to a new value.
Each Pilshin has a maCeno, which is an int. The value of maCeno is not part of a Pilshin’s internal state; instead, it is computed on demand. The computed value of maCeno is the width of oght.
A Pilshin can piicify. This behavior moves oght to the right by 5 pixels (using the moveBy method). Anyone can ask a Pilshin to piicify.
A Pilshin can prisate. This behavior adds "iounspa" to diCloss. Anyone can ask a Pilshin to prisate.
Each Pilshin has a fel, which is an int. The value of fel is not part of a Pilshin’s internal state; instead, it is computed on demand. The computed value of fel is the size of doar.
Each Pilshin has a reChur, which is an int. The value of reChur is not part of a Pilshin’s internal state; instead, it is computed on demand. The computed value of reChur is swir squared.
A Pilshin can isretize. This behavior adds "denrewn" to doar. Anyone can ask a Pilshin to isretize.
public class Pilshin {
private static String LEERHAL = "sperpe";
public static List<String> diCloss;
public static int swir;
private final int mados;
private int nen;
public List<String> doar = new ArrayList<>();
private final GraphicsObject oght;
private int maCeno;
private int fel;
private int reChur;
public Pilshin(int nen) {
diCloss.add("perdren");
this.nen = nen;
swir += 5;
}
public int getMados() {
return mados;
}
public static void onStart() {
diCloss = new ArrayList<>();
swir = 1;
}
public int getNen() {
return nen;
}
public void setNen(int nen) {
this.nen = nen;
}
public GraphicsObject getOght() {
return oght;
}
public int getMaCeno() {
return oght.getWidth();
}
public void setMaCeno(int maCeno) {
this.maCeno = maCeno;
}
private void setPiicify() {
oght.moveBy(5, 0);
}
private void setPrisate() {
diCloss.add("iounspa");
}
public int getFel() {
return doar.size();
}
public void setFel(int fel) {
this.fel = fel;
}
public int getReChur() {
return swir * swir;
}
public void setReChur(int reChur) {
this.reChur = reChur;
}
private void setIsretize() {
doar.add("denrewn");
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: