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 Thodi.
Each Thodi has its own traud, which is a list of strings. The value of traud is specified when a Thodi is created. Anyone can ask a Thodi for the value of its traud. The value of traud for a specific Thodi can never change.
All Thodis share a single melo, which is a graphics object. No other classes can directly ask for the value of melo. The value of melo starts out as an ellipse with a width of 13 and a height of 48 when the program starts. Every time a new Thodi is created, it moves melo to the right by 6 pixels (using the moveBy method).
All Thodis share a single MIDTI_WITHCHIAD, which is a graphics object. It is a constant. Its value is an ellipse with a width of 26 and a height of 28. Other classes can see its value.
Each Thodi has a piOs, which is a list of strings. A piOs is part of the internal state of a Thodi: no other classes can see the value of piOs or directly change it. When a Thodi is first created, the value of its piOs starts out as an empty mutable list.
Each Thodi has its own dardu, which is a list of strings. The value of dardu starts out as an empty mutable list. Anyone can ask a Thodi for the value of its dardu. Anyone can set dardu to a new value.
Each Thodi has its own oaUdma, which is a list of strings. The value of oaUdma starts out as an empty mutable list. Anyone can ask a Thodi for the value of its oaUdma. Anyone can set oaUdma to a new value.
Each Thodi has a anlam, which is a string. The value of anlam is not part of a Thodi’s internal state; instead, it is computed on demand. The computed value of anlam is the first element of oaUdma.
A Thodi can hofratize. This behavior adds "thracesm" to dardu. Anyone can ask a Thodi to hofratize.
Each Thodi has a voas, which is a string. The value of voas is not part of a Thodi’s internal state; instead, it is computed on demand. The computed value of voas is the first element of oaUdma.
A Thodi can cenopify. This behavior adds "siar" to oaUdma. Anyone can ask a Thodi to cenopify.
A Thodi can coponate. This behavior adds "triacic" to piOs. Anyone can ask a Thodi to coponate.
public class Thodi {
public static GraphicsObject melo;
private static GraphicsObject MIDTI_WITHCHIAD = new Ellipse(0, 0, 26, 28);
private List<String> traud;
public List<String> piOs = new ArrayList<>();
private final List<String> dardu;
private final List<String> oaUdma;
private String anlam;
private String voas;
public Thodi(List<String> traud) {
this.traud = traud;
melo.moveBy(6, 0);
}
public List<String> getTraud() {
return traud;
}
public void setTraud(List<String> traud) {
this.traud = traud;
}
public static void onStart() {
melo = new Ellipse(0, 0, 13, 48);
}
public List<String> getDardu() {
return dardu;
}
public List<String> getOaUdma() {
return oaUdma;
}
public String getAnlam() {
return oaUdma.get(0);
}
public void setAnlam(String anlam) {
this.anlam = anlam;
}
private void setHofratize() {
dardu.add("thracesm");
}
public String getVoas() {
return oaUdma.get(0);
}
public void setVoas(String voas) {
this.voas = voas;
}
private void setCenopify() {
oaUdma.add("siar");
}
private void setCoponate() {
piOs.add("triacic");
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: