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 an Unji.
All Unjis share a single VAPTWREC, which is an int. It is a constant. Its value is 7. Other classes can see its value.
Each Unji has its own anDu, which is an int. The value of anDu is specified when a Unji is created. Anyone can ask an Unji for the value of its anDu. The value of anDu for a specific Unji can never change.
Each Unji has a fos, which is an int. The value of fos is not part of an Unji’s internal state; instead, it is computed on demand. The computed value of fos is anDu squared.
public class Unji {
private final int VAPTWREC = 7;
private int anDu;
private int fos;
public Unji(int anDu) {
this.anDu = anDu;
}
public int getAnDu() {
return anDu;
}
public void setAnDu(int anDu) {
this.anDu = anDu;
}
public int getFos() {
return anDu * anDu;
}
public void setFos(int fos) {
this.fos = fos;
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: