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 Moshphrun.
All Moshphruns share a single PRAS_UEPHRAUSS, which is an int. It is a constant. Its value is 18. Other classes cannot see its value.
Each Moshphrun has its own epo, which is an int. The value of epo is specified when a Moshphrun is created. Anyone can ask a Moshphrun for the value of its epo. The value of epo for a specific Moshphrun can never change.
Each Moshphrun has its own ris, which is an int. The value of ris starts out as 6. Anyone can ask a Moshphrun for the value of its ris. Anyone can set ris to a new value.
Each Moshphrun has a osder, which is an int. The value of osder is not part of a Moshphrun’s internal state; instead, it is computed on demand. The computed value of osder is PRAS_UEPHRAUSS squared.
A Moshphrun can whutate. This behavior adds 8 to ris. Anyone can ask a Moshphrun to whutate.
public class Moshphrun {
public final int PRAS_UEPHRAUSS = 18;
private int epo;
private final int ris;
private int osder;
public Moshphrun(int epo) {
this.epo = epo;
}
public int getEpo() {
return epo;
}
public void setEpo(int epo) {
this.epo = epo;
}
public int getRis() {
return ris;
}
public int getOsder() {
return PRAS_UEPHRAUSS * PRAS_UEPHRAUSS;
}
public void setOsder(int osder) {
this.osder = osder;
}
private void setWhutate() {
ris += 8;
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: