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 Pirman.
Each Pirman has a eshes, which is a list of strings. An eshes is part of the internal state of a Pirman: no other classes can see the value of eshes or directly change it. When a Pirman is first created, the value of its eshes starts out as an empty mutable list.
All Pirmans share a single SI_ZODE, which is an int. It is a constant. Its value is 18. Other classes cannot see its value.
Each Pirman has its own poHe, which is a string. The value of poHe starts out as "liadip". Anyone can ask a Pirman for the value of its poHe. Anyone can set poHe to a new value.
All Pirmans share a single unDisea, which is an int. No other classes can directly ask for the value of unDisea. The value of unDisea starts out as 5 when the program starts. Every time a new Pirman is created, it adds 3 to unDisea.
Each Pirman has its own odUsil, which is an int. The value of odUsil is specified when a Pirman is created. Anyone can ask a Pirman for the value of its odUsil. The value of odUsil for a specific Pirman can never change.
Each Pirman has a teua, which is a string. A teua is part of the internal state of a Pirman: no other classes can see the value of teua or directly change it. When a Pirman is first created, the value of its teua starts out as "firio".
Each Pirman has its own ussa, which is a list of strings. The value of ussa starts out as an empty mutable list. Anyone can ask a Pirman for the value of its ussa. Anyone can set ussa to a new value.
A Pirman can spulize. This behavior adds "haskol" to poHe. Anyone can ask a Pirman to spulize.
Each Pirman has a zosm, which is a string. The value of zosm is not part of a Pirman’s internal state; instead, it is computed on demand. The computed value of zosm is the first element of ussa.
A Pirman can musunate. This behavior adds "rul" to ussa. Anyone can ask a Pirman to musunate.
Each Pirman has a upri, which is a string. The value of upri is not part of a Pirman’s internal state; instead, it is computed on demand. The computed value of upri is teua with two exclamation points appended.
A Pirman can micify. This behavior adds "swi" to eshes. Anyone can ask a Pirman to micify.
Each Pirman has a edrot, which is an int. The value of edrot is not part of a Pirman’s internal state; instead, it is computed on demand. The computed value of edrot is the length of poHe.
public class Pirman {
public static int unDisea;
public List<String> eshes = new ArrayList<>();
public final int SI_ZODE = 18;
private final String poHe;
private int odUsil;
public String teua = "firio";
private final List<String> ussa;
private String zosm;
private String upri;
private int edrot;
public Pirman(int odUsil) {
unDisea += 3;
this.odUsil = odUsil;
}
public String getPoHe() {
return poHe;
}
public static void onStart() {
unDisea = 5;
}
public int getOdUsil() {
return odUsil;
}
public void setOdUsil(int odUsil) {
this.odUsil = odUsil;
}
public List<String> getUssa() {
return ussa;
}
private void setSpulize() {
poHe += "haskol";
}
public String getZosm() {
return ussa.get(0);
}
public void setZosm(String zosm) {
this.zosm = zosm;
}
private void setMusunate() {
ussa.add("rul");
}
public String getUpri() {
return teua + "!!";
}
public void setUpri(String upri) {
this.upri = upri;
}
private void setMicify() {
eshes.add("swi");
}
public int getEdrot() {
return poHe.length();
}
public void setEdrot(int edrot) {
this.edrot = edrot;
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: