Bank charges

The problem

A bank account charges $10 per month plus the following check fees for a commercial checking account:

  • $.10 each for fewer than 20 checks
  • $.08 each for 20-39 checks
  • $.06 each for 40-59 checks
  • $.04 each for 60 or more checks

Write a program that asks for the number of checks written for the month. The program should then calculate and display the bank's services fees for the month.

Breaking it down

static double BASE_FEE = 10;
public static void main(String[] args) {

    // define rages for checks
    RangeMap<Integer, Double> checkFee = TreeRangeMap.create();
    checkFee.put(Range.closed(0, 19), .1);
    checkFee.put(Range.closed(20, 39), .8);
    checkFee.put(Range.closed(40, 59), .6);
    checkFee.put(Range.closed(60, Integer.MAX_VALUE), .4);

    // Create a Scanner object for keyboard input.
    Scanner keyboard = new Scanner(;

    // Get the number of checks written.
    System.out.print("Enter the number of checks written " + "this month: ");
    int numChecks = keyboard.nextInt();

    //close scanner

    // calculate total fee
    double total = BASE_FEE + (checkFee.get(numChecks) * numChecks); 
    // Display the total bank fees.
    System.out.printf("The total fees are $%.2f\n", total);


Enter the number of checks written this month: 100
The total fees are $50.00

Level Up

  • Create a method called checkFee that returns a double and refactor the logic to calculate the total check fee into this method.
  • Write a unit test for checkFee and for the determining the check fees, is there an error?