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 Hipon.
Each Hipon has its own osNes, which is an int. The value of osNes is specified when a Hipon is created. Anyone can ask a Hipon for the value of its osNes. The value of osNes for a specific Hipon can never change.
All Hipons share a single calt, which is a list of strings. No other classes can directly ask for the value of calt. The value of calt starts out as an empty mutable list when the program starts. Every time a new Hipon is created, it adds "spijin" to calt.
Each Hipon has its own pipre, which is an int. The value of pipre starts out as 19. Anyone can ask a Hipon for the value of its pipre. Anyone can set pipre to a new value.
Each Hipon has a oip, which is an int. The value of oip is not part of a Hipon’s internal state; instead, it is computed on demand. The computed value of oip is pipre plus 3.
A Hipon can hidinify. This behavior adds 2 to pipre. Anyone can ask a Hipon to hidinify.
public class Hipon {
public static List<String> calt;
private int osNes;
private final int pipre;
private int oip;
public Hipon(int osNes) {
this.osNes = osNes;
calt.add("spijin");
}
public int getOsNes() {
return osNes;
}
public void setOsNes(int osNes) {
this.osNes = osNes;
}
public static void onStart() {
calt = new ArrayList<>();
}
public int getPipre() {
return pipre;
}
public int getOip() {
return pipre + 3;
}
public void setOip(int oip) {
this.oip = oip;
}
private void setHidinify() {
pipre += 2;
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: