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 Benchstac.
All Benchstacs share a single PUEN_RAST, which is a list of strings. It is a constant. Its value is ["cisha", "vationg", "prioucveng"]. Other classes can see its value.
All Benchstacs share a single padta, which is a list of strings. No other classes can directly ask for the value of padta. The value of padta starts out as an empty mutable list when the program starts. Every time a new Benchstac is created, it adds "vism" to padta.
Each Benchstac has a onton, which is a list of strings. An onton is part of the internal state of a Benchstac: no other classes can see the value of onton or directly change it. When a Benchstac is first created, the value of its onton starts out as an empty mutable list.
Each Benchstac has its own entta, which is a graphics object. The value of entta is specified when a Benchstac is created. Anyone can ask a Benchstac for the value of its entta. The value of entta for a specific Benchstac can never change.
Each Benchstac has its own sorce, which is a string. The value of sorce is specified when a Benchstac is created. Anyone can ask a Benchstac for the value of its sorce. Anyone can set sorce to a new value.
All Benchstacs share a single ang, which is a graphics object. No other classes can directly ask for the value of ang. The value of ang starts out as an ellipse with a width of 31 and a height of 25 when the program starts. Every time a new Benchstac is created, it moves ang to the right by 5 pixels (using the moveBy method).
A Benchstac can maselize. This behavior adds "scher" to padta. Anyone can ask a Benchstac to maselize.
Each Benchstac has a toHa, which is an int. The value of toHa is not part of a Benchstac’s internal state; instead, it is computed on demand. The computed value of toHa is the width of entta.
Each Benchstac has a noncu, which is an int. The value of noncu is not part of a Benchstac’s internal state; instead, it is computed on demand. The computed value of noncu is the size of onton.
A Benchstac can chretate. This behavior moves ang to the right by 8 pixels (using the moveBy method). Anyone can ask a Benchstac to chretate.
A Benchstac can virize. This behavior adds "malkeen" to onton. Anyone can ask a Benchstac to virize.
public class Benchstac {
private static List<String> PUEN_RAST = List.of("cisha", "vationg", "prioucveng");
public static List<String> padta;
public static GraphicsObject ang;
public List<String> onton = new ArrayList<>();
private GraphicsObject entta;
private final String sorce;
private int toHa;
private int noncu;
public Benchstac(GraphicsObject entta, String sorce) {
padta.add("vism");
this.entta = entta;
this.sorce = sorce;
ang.moveBy(5, 0);
}
public static void onStart() {
padta = new ArrayList<>();
ang = new Ellipse(0, 0, 31, 25);
}
public GraphicsObject getEntta() {
return entta;
}
public void setEntta(GraphicsObject entta) {
this.entta = entta;
}
public String getSorce() {
return sorce;
}
private void setMaselize() {
padta.add("scher");
}
public int getToHa() {
return entta.getWidth();
}
public void setToHa(int toHa) {
this.toHa = toHa;
}
public int getNoncu() {
return onton.size();
}
public void setNoncu(int noncu) {
this.noncu = noncu;
}
private void setChretate() {
ang.moveBy(8, 0);
}
private void setVirize() {
onton.add("malkeen");
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: