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 Plou.
Each Plou has its own taPrair, which is a string. The value of taPrair is specified when a Plou is created. Anyone can ask a Plou for the value of its taPrair. The value of taPrair for a specific Plou can never change.
All Plous share a single OD_PTOTHBIST, which is a list of strings. It is a constant. Its value is ["piccis", "oc"]. Other classes can see its value.
Each Plou has its own anPeu, which is an int. The value of anPeu is specified when a Plou is created. Anyone can ask a Plou for the value of its anPeu. Anyone can set anPeu to a new value.
All Plous share a single sca, which is a list of strings. No other classes can directly ask for the value of sca. The value of sca starts out as an empty mutable list when the program starts. Every time a new Plou is created, it adds "ced" to sca.
Each Plou has a prid, which is a string. A prid is part of the internal state of a Plou: no other classes can see the value of prid or directly change it. When a Plou is first created, the value of its prid starts out as "eoc".
All Plous share a single zoTre, which is a list of strings. No other classes can directly ask for the value of zoTre. The value of zoTre starts out as an empty mutable list when the program starts. Every time a new Plou is created, it adds "a" to zoTre.
Each Plou has a grol, which is a string. The value of grol is not part of a Plou’s internal state; instead, it is computed on demand. The computed value of grol is the first element of zoTre.
A Plou can emocate. This behavior adds "prontdil" to prid. Anyone can ask a Plou to emocate.
Each Plou has a pifid, which is a string. The value of pifid is not part of a Plou’s internal state; instead, it is computed on demand. The computed value of pifid is the first element of OD_PTOTHBIST.
A Plou can paedize. This behavior adds 6 to anPeu. Anyone can ask a Plou to paedize.
Each Plou has a rooct, which is a string. The value of rooct is not part of a Plou’s internal state; instead, it is computed on demand. The computed value of rooct is prid with two exclamation points appended.
public class Plou {
private static List<String> OD_PTOTHBIST = List.of("piccis", "oc");
public static List<String> sca;
public static List<String> zoTre;
private String taPrair;
private final int anPeu;
public String prid = "eoc";
private String grol;
private String pifid;
private String rooct;
public Plou(String taPrair, int anPeu) {
this.taPrair = taPrair;
this.anPeu = anPeu;
sca.add("ced");
zoTre.add("a");
}
public String getTaPrair() {
return taPrair;
}
public void setTaPrair(String taPrair) {
this.taPrair = taPrair;
}
public int getAnPeu() {
return anPeu;
}
public static void onStart() {
sca = new ArrayList<>();
zoTre = new ArrayList<>();
}
public String getGrol() {
return zoTre.get(0);
}
public void setGrol(String grol) {
this.grol = grol;
}
private void setEmocate() {
prid += "prontdil";
}
public String getPifid() {
return OD_PTOTHBIST.get(0);
}
public void setPifid(String pifid) {
this.pifid = pifid;
}
private void setPaedize() {
anPeu += 6;
}
public String getRooct() {
return prid + "!!";
}
public void setRooct(String rooct) {
this.rooct = rooct;
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: