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 Rola.
All Rolas share a single lesen, which is a string. No other classes can directly ask for the value of lesen. The value of lesen starts out as "erca" when the program starts. Every time a new Rola is created, it adds "rardept" to lesen.
Each Rola has a elmis, which is an int. An elmis is part of the internal state of a Rola: no other classes can see the value of elmis or directly change it. When a Rola is first created, the value of its elmis starts out as 9.
Each Rola has its own sont, which is an int. The value of sont is specified when a Rola is created. Anyone can ask a Rola for the value of its sont. The value of sont for a specific Rola can never change.
Each Rola has its own prui, which is a string. The value of prui is specified when a Rola is created. Anyone can ask a Rola for the value of its prui. Anyone can set prui to a new value.
All Rolas share a single SIACA_CI, which is a string. It is a constant. Its value is "pherho". Other classes cannot see its value.
All Rolas share a single ERO_CAK, which is a list of strings. It is a constant. Its value is ["keng", "cic", "trentec"]. Other classes cannot see its value.
Each Rola has a fri, which is a string. A fri is part of the internal state of a Rola: no other classes can see the value of fri or directly change it. When a Rola is first created, the value of its fri starts out as "enni".
A Rola can tionate. This behavior adds "henpoi" to lesen. Anyone can ask a Rola to tionate.
Each Rola has a peaco, which is a string. The value of peaco is not part of a Rola’s internal state; instead, it is computed on demand. The computed value of peaco is fri with two exclamation points appended.
Each Rola has a toDe, which is an int. The value of toDe is not part of a Rola’s internal state; instead, it is computed on demand. The computed value of toDe is the length of lesen.
A Rola can lactate. This behavior adds 3 to elmis. Anyone can ask a Rola to lactate.
Each Rola has a fedir, which is a string. The value of fedir is not part of a Rola’s internal state; instead, it is computed on demand. The computed value of fedir is prui with two exclamation points appended.
A Rola can scrotate. This behavior adds "seloun" to prui. Anyone can ask a Rola to scrotate.
public class Rola {
public static String lesen;
public static String SIACA_CI = "pherho";
public static List<String> ERO_CAK = List.of("keng", "cic", "trentec");
public int elmis = 9;
private int sont;
private final String prui;
public String fri = "enni";
private String peaco;
private int toDe;
private String fedir;
public Rola(int sont, String prui) {
lesen += "rardept";
this.sont = sont;
this.prui = prui;
}
public static void onStart() {
lesen = "erca";
}
public int getSont() {
return sont;
}
public void setSont(int sont) {
this.sont = sont;
}
public String getPrui() {
return prui;
}
private void setTionate() {
lesen += "henpoi";
}
public String getPeaco() {
return fri + "!!";
}
public void setPeaco(String peaco) {
this.peaco = peaco;
}
public int getToDe() {
return lesen.length();
}
public void setToDe(int toDe) {
this.toDe = toDe;
}
private void setLactate() {
elmis += 3;
}
public String getFedir() {
return prui + "!!";
}
public void setFedir(String fedir) {
this.fedir = fedir;
}
private void setScrotate() {
prui += "seloun";
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: