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 Tangboc.
Each Tangboc has a oaorm, which is an int. An oaorm is part of the internal state of a Tangboc: no other classes can see the value of oaorm or directly change it. When a Tangboc is first created, the value of its oaorm starts out as 14.
All Tangbocs share a single esJio, which is an int. No other classes can directly ask for the value of esJio. The value of esJio starts out as 19 when the program starts. Every time a new Tangboc is created, it adds 2 to esJio.
Each Tangboc has its own chall, which is an int. The value of chall starts out as 4. Anyone can ask a Tangboc for the value of its chall. Anyone can set chall to a new value.
Each Tangboc has its own ceid, which is an int. The value of ceid is specified when a Tangboc is created. Anyone can ask a Tangboc for the value of its ceid. The value of ceid for a specific Tangboc can never change.
Each Tangboc has a beRoint, which is an int. The value of beRoint is not part of a Tangboc’s internal state; instead, it is computed on demand. The computed value of beRoint is ceid plus 3.
A Tangboc can onprelate. This behavior adds 4 to esJio. Anyone can ask a Tangboc to onprelate.
Each Tangboc has a onpot, which is an int. The value of onpot is not part of a Tangboc’s internal state; instead, it is computed on demand. The computed value of onpot is esJio squared.
public class Tangboc {
public static int esJio;
public int oaorm = 14;
private final int chall;
private int ceid;
private int beRoint;
private int onpot;
public Tangboc(int ceid) {
esJio += 2;
this.ceid = ceid;
}
public static void onStart() {
esJio = 19;
}
public int getChall() {
return chall;
}
public int getCeid() {
return ceid;
}
public void setCeid(int ceid) {
this.ceid = ceid;
}
public int getBeRoint() {
return ceid + 3;
}
public void setBeRoint(int beRoint) {
this.beRoint = beRoint;
}
private void setOnprelate() {
esJio += 4;
}
public int getOnpot() {
return esJio * esJio;
}
public void setOnpot(int onpot) {
this.onpot = onpot;
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: