Mam takie pytanko, a mianowicie mam przykładowe metody:
public class OtherClass{
private double cash;
private double one;
private double two;
private double three;
private final double percentDivisor = 100;
private double countPercent(){
return (1 + ((one + two + three)/percentDivisor));
}
public double getCashFromPercent(){
return cash * countPercent();
}
public OtherClass(double cash, double one, double two, double three){
this.cash = cash;
this.one = one;
...
}
}
Wywołanie:
else_button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
otherClass = new OtherClass(1000, 5, 5, 5);
else_label.setText(Double.parseDouble(otherClass.getCashFromPercent()));
}
Po wykonaniu zdarzenia objekt "else_label" dostaje wartość '1000.0' zamiast '1150.0'. I podobnie jest z innymi wartościami dopóki wartość metody "countPercent()" nie osiągnie wartości całkowitej wtedy cash jest jest mnożony przez liczbę naturalną.
Moje pytanie dlaczego tak się dzieje i jak temu zaradzić?