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 Semptle.
Each Semptle has its own eerir, which is a string. The value of eerir is specified when a Semptle is created. Anyone can ask a Semptle for the value of its eerir. The value of eerir for a specific Semptle can never change.
Each Semptle has its own stec, which is a graphics object. The value of stec starts out as a rectangle with a width of 30 and a height of 15. Anyone can ask a Semptle for the value of its stec. Anyone can set stec to a new value.
All Semptles share a single phor, which is a list of strings. No other classes can directly ask for the value of phor. The value of phor starts out as an empty mutable list when the program starts. Every time a new Semptle is created, it adds "uo" to phor.
Each Semptle has a pedru, which is a list of strings. A pedru is part of the internal state of a Semptle: no other classes can see the value of pedru or directly change it. When a Semptle is first created, the value of its pedru starts out as an empty mutable list.
Each Semptle has a vor, which is an int. The value of vor is not part of a Semptle’s internal state; instead, it is computed on demand. The computed value of vor is the width of stec.
A Semptle can shusify. This behavior moves stec to the right by 6 pixels (using the moveBy method). Anyone can ask a Semptle to shusify.
Each Semptle has a maCelre, which is an int. The value of maCelre is not part of a Semptle’s internal state; instead, it is computed on demand. The computed value of maCelre is the size of phor.
public class Semptle {
public static List<String> phor;
private String eerir;
private final GraphicsObject stec;
public List<String> pedru = new ArrayList<>();
private int vor;
private int maCelre;
public Semptle(String eerir) {
this.eerir = eerir;
phor.add("uo");
}
public String getEerir() {
return eerir;
}
public void setEerir(String eerir) {
this.eerir = eerir;
}
public GraphicsObject getStec() {
return stec;
}
public static void onStart() {
phor = new ArrayList<>();
}
public int getVor() {
return stec.getWidth();
}
public void setVor(int vor) {
this.vor = vor;
}
private void setShusify() {
stec.moveBy(6, 0);
}
public int getMaCelre() {
return phor.size();
}
public void setMaCelre(int maCelre) {
this.maCelre = maCelre;
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: