Results 1 to 14 of 14
  1. #1
    heyya99 is offline Member
    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0

    Default Interest Calculator Design

    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.

    Any help is welcome.

    Java Code:
    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;
    	}
    Last edited by heyya99; 04-09-2013 at 09:24 PM.

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Interest Calculator Design

    Hi heyya99, welcome to the forums.

    A quick and easy solution would be be to pass another argument into the method which says how long the customer has been with the bank or the date they joined. You could the perform calcations based on the value which has been passed in.

    Another option would be to create a Customer object which contains the date the customer joined the bank. You could the perform the calcualtion based on the difference between when the customer joined and the current date. The benefit of creating a Customer class is that you could also add additonal values and properties such as name, marital status, date of birth, etc.

    Regards.

  3. #3
    heyya99 is offline Member
    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0

    Default Re: Interest Calculator Design

    Quote Originally Posted by Ronin View Post
    Hi heyya99, welcome to the forums.

    A quick and easy solution would be be to pass another argument into the method which says how long the customer has been with the bank or the date they joined. You could the perform calcations based on the value which has been passed in.

    Another option would be to create a Customer object which contains the date the customer joined the bank. You could the perform the calcualtion based on the difference between when the customer joined and the current date. The benefit of creating a Customer class is that you could also add additonal values and properties such as name, marital status, date of birth, etc.

    Regards.
    Thanks!

    I'm trying to find a method of storing the years with bank, rate and money threshold. If a bank manager decided to add a new rate, I'd like to allow them to do it with minimal changes. I've been thinking of a map (years as key and an array as value). The array could hold the threshold and the rate. What do you think of that? The solution has to be simple.

  4. #4
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Interest Calculator Design

    That solution could work but there are a couple of things to bear in mind.
    You want the array to store both the rate and thresholds which would mean that for each new entry you would be adding two elements in the array. As such using the indexes to represent the number of years means you would have to halve this value and add one to get the number of years.
    Instead you could use an array of Rate objects which contains all of the relevant information.

    When you said you want the solution to be simple, is there a specific reason for this?

    Regards.

  5. #5
    heyya99 is offline Member
    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0

    Default Re: Interest Calculator Design

    Quote Originally Posted by Ronin View Post
    That solution could work but there are a couple of things to bear in mind.
    You want the array to store both the rate and thresholds which would mean that for each new entry you would be adding two elements in the array. As such using the indexes to represent the number of years means you would have to halve this value and add one to get the number of years.
    Instead you could use an array of Rate objects which contains all of the relevant information.

    When you said you want the solution to be simple, is there a specific reason for this?

    Regards.
    I wasn't suggesting using an array index for the year, I meant having a map with the year for it's key, then each value would be a 2 element array (threshold and rate). Does that make sense?

    The app is for a job interview and I've been told overly complicated solutions are being rejected.

    Do you think reading rates from a text file is a good solution?

  6. #6
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Interest Calculator Design

    Ah, I see. I would not consider using simple objects as complicated, by that definition anything beyond a simple "Hello World" program is complicated.

    As for the text file, if the application needs a way to store the information when it is not running then you would need a file to store the information in. Using objects in a similar way may mean they need to be serializable to store them in files but is this considered complicated?

    An interview is an opportunity to demonstrate your abilities. Can you get the job done without the need to "show off" but create something which achieves the requirements.
    Your overall solution depends on your initial brief and no two solutions are likely to be the same. At a guess the interviewers would be looking for your ideas and the way you approached the solution as much as your final implementation.

    Regards.

  7. #7
    heyya99 is offline Member
    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0

    Default Re: Interest Calculator Design

    Quote Originally Posted by Ronin View Post
    Ah, I see. I would not consider using simple objects as complicated, by that definition anything beyond a simple "Hello World" program is complicated.

    As for the text file, if the application needs a way to store the information when it is not running then you would need a file to store the information in. Using objects in a similar way may mean they need to be serializable to store them in files but is this considered complicated?

    An interview is an opportunity to demonstrate your abilities. Can you get the job done without the need to "show off" but create something which achieves the requirements.
    Your overall solution depends on your initial brief and no two solutions are likely to be the same. At a guess the interviewers would be looking for your ideas and the way you approached the solution as much as your final implementation.

    Regards.
    I hear you.

    Here's my suggestion. I create an class called Rate with 2 variables: rate and threshold. I then create an Array that holds each rate. To find the correct interest rate, I use the array's index to find the correct Rate object. When I've found the object, I use the balance threshold to find the rate.

    If a new rate is to be added, a create a new Rate object and add it to the ArrayList.

  8. #8
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Interest Calculator Design

    Just thinking about it, you may also be able to use enums instead of objects.

    Regards.

  9. #9
    heyya99 is offline Member
    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0

    Default Re: Interest Calculator Design

    Quote Originally Posted by Ronin View Post
    Just thinking about it, you may also be able to use enums instead of objects.

    Regards.
    But how would I store those objects or enums? Map?

  10. #10
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Interest Calculator Design

    A Map is certainly one way to do it, you could also use a simple array.
    Whatever solution you use you need to bear in mind how you are going to reference the correct element. I'm not going say use one method over another as this is your project for your interview. When you're asked why you chose to use a Map or array over another method, you will need to validate your decision and I don't think "Because someone on the internet told me to" would suffice.

    Regards.

  11. #11
    heyya99 is offline Member
    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0

    Default Re: Interest Calculator Design

    Quote Originally Posted by Ronin View Post
    A Map is certainly one way to do it, you could also use a simple array.
    Whatever solution you use you need to bear in mind how you are going to reference the correct element. I'm not going say use one method over another as this is your project for your interview. When you're asked why you chose to use a Map or array over another method, you will need to validate your decision and I don't think "Because someone on the internet told me to" would suffice.

    Regards.
    Thanks. I get you.

    Do you think a Strategy pattern would be a good solution?

  12. #12
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Interest Calculator Design

    I would say it might be slightly above their requirements for the assignment but then I'm not assessing it.

    Regards.

  13. #13
    heyya99 is offline Member
    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0

    Default Re: Interest Calculator Design

    Quote Originally Posted by Ronin View Post
    I would say it might be slightly above their requirements for the assignment but then I'm not assessing it.

    Regards.
    Agreed. I have a working version finished where I have a a map of (year:arrayList) and each array list has a rate class. I find the right array list by passing in the year. I then loop over the rate objects and find the rate that my balance corresponds to.

    To add a new year and subsequent set of bands, I need to create a new rate arrayList and add it to the map, e.g. (3:new ArrayList). To me that's still a bit off effort to have to add a new band. Or am I expecting too much?

  14. #14
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Interest Calculator Design

    I don't think you are as long as you can validate your design decision.

    Oh, and good luck.

    Regards.

Similar Threads

  1. interest for banks
    By lagowon in forum New To Java
    Replies: 2
    Last Post: 11-21-2011, 02:58 AM
  2. Did I do this right? (Interest calculator)
    By r0sedeanne in forum New To Java
    Replies: 7
    Last Post: 09-13-2011, 10:27 AM
  3. Adding Interest to a Bank Account
    By petur170 in forum New To Java
    Replies: 20
    Last Post: 05-26-2011, 02:28 AM
  4. Calculate Interest
    By hacikho in forum New To Java
    Replies: 4
    Last Post: 10-09-2010, 04:15 AM
  5. HELP FAST!!----Interest Calculator
    By Coop33 in forum New To Java
    Replies: 8
    Last Post: 10-15-2008, 01:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •