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 Sepac.
Each Sepac has a saAl, which is a graphics object. A saAl is part of the internal state of a Sepac: no other classes can see the value of saAl or directly change it. When a Sepac is first created, the value of its saAl starts out as a rectangle with a width of 45 and a height of 45.
All Sepacs share a single jopre, which is an int. No other classes can directly ask for the value of jopre. The value of jopre starts out as 4 when the program starts. Every time a new Sepac is created, it adds 8 to jopre.
Each Sepac has its own puUafpe, which is an int. The value of puUafpe is specified when a Sepac is created. Anyone can ask a Sepac for the value of its puUafpe. The value of puUafpe for a specific Sepac can never change.
A Sepac can alestate. This behavior moves saAl to the right by 8 pixels (using the moveBy method). Anyone can ask a Sepac to alestate.
Each Sepac has a fomon, which is an int. The value of fomon is not part of a Sepac’s internal state; instead, it is computed on demand. The computed value of fomon is the x position of saAl.
public class Sepac {
public static int jopre;
public GraphicsObject saAl = new Rectangle(0, 0, 45, 45);
private int puUafpe;
private int fomon;
public Sepac(int puUafpe) {
jopre += 8;
this.puUafpe = puUafpe;
}
public static void onStart() {
jopre = 4;
}
public int getPuUafpe() {
return puUafpe;
}
public void setPuUafpe(int puUafpe) {
this.puUafpe = puUafpe;
}
private void setAlestate() {
saAl.moveBy(8, 0);
}
public int getFomon() {
return saAl.getX();
}
public void setFomon(int fomon) {
this.fomon = fomon;
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: