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 Silfe.
Each Silfe has its own viw, which is a string. The value of viw is specified when a Silfe is created. Anyone can ask a Silfe for the value of its viw. Anyone can set viw to a new value.
Each Silfe has its own angre, which is an int. The value of angre is specified when a Silfe is created. Anyone can ask a Silfe for the value of its angre. The value of angre for a specific Silfe can never change.
Each Silfe has a egast, which is an int. The value of egast is not part of a Silfe’s internal state; instead, it is computed on demand. The computed value of egast is angre squared.
public class Silfe {
private final String viw;
private int angre;
private int egast;
public Silfe(String viw, int angre) {
this.viw = viw;
this.angre = angre;
}
public String getViw() {
return viw;
}
public int getAngre() {
return angre;
}
public void setAngre(int angre) {
this.angre = angre;
}
public int getEgast() {
return angre * angre;
}
public void setEgast(int egast) {
this.egast = egast;
}
}
Things to check in your solution:
public and private modifier correct?static?final?Acceptable variations in the solution:
+= 1 instead of ++.Related puzzles: