how do i get my program to add a $15 fee if the balance falls below $400

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blknmld69
    New Member
    • Feb 2010
    • 69

    #1

    how do i get my program to add a $15 fee if the balance falls below $400

    How do i get my program to add a $15 fee if the balance falls below $400?


    Code:
       import java.util.Scanner; // Needed for the Scanner class
    	
       public class BankCharges
       {
          public static void main(String[] args)
          {
          // Named constants
             final double BASE_FEE = 10.0;
             final double LEVEL_1_FEE = 0.10;
             final double LEVEL_2_FEE = 0.08;
             final double LEVEL_3_FEE = 0.06;
             final double LEVEL_4_FEE = 0.04;
    			final double BANK_FEE =15.0;
    									
          // Create a Scanner object for keybord input.
             Scanner keyboard = new Scanner(System.in);
    			
    		// Get the account balance.
    			System.out.print("Enter your account balance: ");
    			int balance = keyboard.nextInt();
    			
    		// Test for balance below $400.
    			if (balance < 400)
    			{
    				 double totalFee = BASE_FEE + BANK_FEE;
    			}	
    				
          // Get the number of checks written.
             System.out.print("Enter the number of checks written " +
                "this month: ");
             int numChecks = keyboard.nextInt();
    			
          // Test for negative number and if found terminate
             if (numChecks < 0)
             {
                System.out.println("Invalid Input: Negative number entered. Program terminating!");
             }
    			
          // The total fee starts as the base fee.
             double totalFee = BASE_FEE;
    			
          // Add the appropriate per-check fees.
             if (numChecks < 20 && balance < 400)
             {
                totalFee += numChecks * LEVEL_1_FEE + BANK_FEE ;
             }
    			
             else if (numChecks >= 20 && numChecks <= 39)
             {
                totalFee += numChecks * LEVEL_2_FEE;
             }
    			
             else if (numChecks >= 40 && numChecks <= 59)
             {
                totalFee += numChecks * LEVEL_3_FEE;
             }
    			
             else if (numChecks >= 60)
             {
                totalFee += numChecks * LEVEL_4_FEE;
             }
    			
             else
             {
    			
             // no action taken, program can terminate
             }
    			
          // Display the total bank fees unless a negative number was entered.
             if (numChecks >= 0)
             {
                System.out.printf("The total fees are $%.2f\n", totalFee);
             }
    			
          } 
       }
    Last edited by Frinavale; Aug 31 '10, 06:56 PM. Reason: Added the question to the thread.
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    It seems to me that you are not tracking the balance of the account as each transaction is processed.

    What you need to do is process each check in turn, and implement the bank fee the first time the balance falls below $400.00.

    Be careful, though. If you charge the fee for every processed check leaving a balance of under $400.00, your customers will rapidly become very testy.

    Cheers!

    Comment

    Working...