I have written a program that, given an amount, returns the interest you would receive on that figure. There are 3 interest rate bands as follows:
- 1% - £0 to £1000
- 2% - £1000 to £5000
- 3% - £5000+
Can anyone tell me if the following is a good solution or are the 'if'if statements too restrictive?
public BigDecimal calc(BigDecimal amt) { if(amt.compareTo(new BigDecimal(1001))==-1){ interest = amt.divide(new BigDecimal("100")); }else if(amt.compareTo(new BigDecimal(5001))==-1){ interest = amt.multiply(0.02); }else{ interest = amt.multiply(0.03); } return interest; }