I have written a program that, given an amount, returns the interest you would receive on that figure for a bank's customer. There are 3 interest rate bands as follows:
1% - £0 to £1000
2% - £1000 to £5000
3% - £5000+
I would like to amend the program to cater for different bands for different customers. If a customer is with the bank for a period of time, she gets a better rate. Here are the new rates:
After one year:
1% - £0 to £1000
2.5% - £1000 to £5000
4% - £5000+
After two years:
2% - £0 to £1000
3% - £1000 to £5000
4% - £5000 to £10000
5% - £10000+
My initial approach is below. Can anyone suggest how I'd go about implementing the additional part? I want the program to be as simple as possible with minimal complexity. I don't want an all-compassing solution, just something that works well and is extensible.
private static BigDecimal ONE_PERCENT = new BigDecimal("0.01"); private static BigDecimal TWO_PERCENT = new BigDecimal("0.02"); private static BigDecimal THREE_PERCENT = new BigDecimal("0.03"); private static BigDecimal ONE_THOUSAND = new BigDecimal("1000"); private static BigDecimal FIVE_THOUSAND = new BigDecimal("5000"); 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; }