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 Hesspreel.
All Hesspreels share a single zePi, which is an int. No other classes can directly ask for the value of zePi. The value of zePi starts out as 4 when the program starts. Every time a new Hesspreel is created, it adds 7 to zePi.
Each Hesspreel has a siOl, which is an int. A siOl is part of the internal state of a Hesspreel: no other classes can see the value of siOl or directly change it. When a Hesspreel is first created, the value of its siOl starts out as 12.
Each Hesspreel has its own teThail, which is a string. The value of teThail is specified when a Hesspreel is created. Anyone can ask a Hesspreel for the value of its teThail. Anyone can set teThail to a new value.
Each Hesspreel has a stro, which is an int. The value of stro is not part of a Hesspreel’s internal state; instead, it is computed on demand. The computed value of stro is the length of teThail.
A Hesspreel can mengenate. This behavior adds "ocing" to teThail. Anyone can ask a Hesspreel to mengenate.
public class Hesspreel {
public static int zePi;
public int siOl = 12;
private final String teThail;
private int stro;
public Hesspreel(String teThail) {
zePi += 7;
this.teThail = teThail;
}
public static void onStart() {
zePi = 4;
}
public String getTeThail() {
return teThail;
}
public int getStro() {
return teThail.length();
}
public void setStro(int stro) {
this.stro = stro;
}
private void setMengenate() {
teThail += "ocing";
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: