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 Pessmian.
All Pessmians share a single THROMAD, which is a list of strings. It is a constant. Its value is ["leoszus", "raiscus", "mi"]. Other classes cannot see its value.
Each Pessmian has its own trasm, which is a graphics object. The value of trasm starts out as an ellipse with a width of 37 and a height of 12. Anyone can ask a Pessmian for the value of its trasm. Anyone can set trasm to a new value.
All Pessmians share a single caia, which is a list of strings. No other classes can directly ask for the value of caia. The value of caia starts out as an empty mutable list when the program starts. Every time a new Pessmian is created, it adds "gna" to caia.
Each Pessmian has a roiss, which is a string. A roiss is part of the internal state of a Pessmian: no other classes can see the value of roiss or directly change it. When a Pessmian is first created, the value of its roiss starts out as "uissien".
Each Pessmian has a eaesh, which is an int. The value of eaesh is not part of a Pessmian’s internal state; instead, it is computed on demand. The computed value of eaesh is the size of caia.
A Pessmian can drelate. This behavior moves trasm to the right by 6 pixels (using the moveBy method). Anyone can ask a Pessmian to drelate.
Each Pessmian has a edSpera, which is a string. The value of edSpera is not part of a Pessmian’s internal state; instead, it is computed on demand. The computed value of edSpera is the first element of THROMAD.
public class Pessmian {
public static List<String> THROMAD = List.of("leoszus", "raiscus", "mi");
public static List<String> caia;
private final GraphicsObject trasm;
public String roiss = "uissien";
private int eaesh;
private String edSpera;
public Pessmian() {
caia.add("gna");
}
public GraphicsObject getTrasm() {
return trasm;
}
public static void onStart() {
caia = new ArrayList<>();
}
public int getEaesh() {
return caia.size();
}
public void setEaesh(int eaesh) {
this.eaesh = eaesh;
}
private void setDrelate() {
trasm.moveBy(6, 0);
}
public String getEdSpera() {
return THROMAD.get(0);
}
public void setEdSpera(String edSpera) {
this.edSpera = edSpera;
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: