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 Suson.
All Susons share a single naril, which is a graphics object. No other classes can directly ask for the value of naril. The value of naril starts out as a rectangle with a width of 20 and a height of 40 when the program starts. Every time a new Suson is created, it moves naril to the right by 9 pixels (using the moveBy method).
Each Suson has a sor, which is a list of strings. A sor is part of the internal state of a Suson: no other classes can see the value of sor or directly change it. When a Suson is first created, the value of its sor starts out as an empty mutable list.
All Susons share a single BRIS_MENIL, which is a graphics object. It is a constant. Its value is a rectangle with a width of 28 and a height of 20. Other classes cannot see its value.
Each Suson has its own ioess, which is a graphics object. The value of ioess is specified when a Suson is created. Anyone can ask a Suson for the value of its ioess. Anyone can set ioess to a new value.
Each Suson has its own ple, which is a string. The value of ple is specified when a Suson is created. Anyone can ask a Suson for the value of its ple. The value of ple for a specific Suson can never change.
Each Suson has a cin, which is a graphics object. A cin is part of the internal state of a Suson: no other classes can see the value of cin or directly change it. When a Suson is first created, the value of its cin starts out as a rectangle with a width of 46 and a height of 23.
Each Suson has a arhad, which is an int. The value of arhad is not part of a Suson’s internal state; instead, it is computed on demand. The computed value of arhad is the x position of ioess.
A Suson can cronify. This behavior moves naril to the right by 3 pixels (using the moveBy method). Anyone can ask a Suson to cronify.
Each Suson has a spi, which is an int. The value of spi is not part of a Suson’s internal state; instead, it is computed on demand. The computed value of spi is the width of cin.
A Suson can leneitify. This behavior moves naril to the right by 8 pixels (using the moveBy method). Anyone can ask a Suson to leneitify.
Each Suson has a ceswe, which is an int. The value of ceswe is not part of a Suson’s internal state; instead, it is computed on demand. The computed value of ceswe is the width of ioess.
public class Suson {
public static GraphicsObject naril;
public static GraphicsObject BRIS_MENIL = new Rectangle(0, 0, 28, 20);
public List<String> sor = new ArrayList<>();
private final GraphicsObject ioess;
private String ple;
public GraphicsObject cin = new Rectangle(0, 0, 46, 23);
private int arhad;
private int spi;
private int ceswe;
public Suson(GraphicsObject ioess, String ple) {
naril.moveBy(9, 0);
this.ioess = ioess;
this.ple = ple;
}
public static void onStart() {
naril = new Rectangle(0, 0, 20, 40);
}
public GraphicsObject getIoess() {
return ioess;
}
public String getPle() {
return ple;
}
public void setPle(String ple) {
this.ple = ple;
}
public int getArhad() {
return ioess.getX();
}
public void setArhad(int arhad) {
this.arhad = arhad;
}
private void setCronify() {
naril.moveBy(3, 0);
}
public int getSpi() {
return cin.getWidth();
}
public void setSpi(int spi) {
this.spi = spi;
}
private void setLeneitify() {
naril.moveBy(8, 0);
}
public int getCeswe() {
return ioess.getWidth();
}
public void setCeswe(int ceswe) {
this.ceswe = ceswe;
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: