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);
}
}
}
Comment