Bank 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
The bank also charges an extra $15 if the balance of the account falls below $400 (before any check fees are applied).
Write a program that asks for the beginning balance and the number of checks written.
Compute and display the bank’s service fees for the month (30 days).
Input Validation: Do not accept a negative value for the number of checks written. If a negative value is given for the beginning balance, display an urgent message indicating the account is overdrawn.
import java.util.Scanner;
public class Main {
 public static void main(String[] args) {
  Scanner s = new Scanner(System.in); 
  int numberOfChecks;
  double accountAmount;
  double endBalance = 0;
  double sumOfCharges = 0;
  System.out.println("Enter account balance ($): ");
  accountAmount = s.nextDouble();
  if (accountAmount < 0) {
   System.out.println("Pay attention! Account is overdrawn!");
   return;
  }
  for (bool i = false; i == false;) {
   System.out.print("Enter number of checks: ");
   numberOfChecks = s.nextInt();
   if (numberOfChecks < 0) {
    System.out.println("Wrong number of checks.");
    continue;
   }
   i = true;
  }
  System.out.println();
  if (accountAmount < 400) {
   System.out.println("Extra charge $15: (balance of the account falls below $400)");
   sumOfCharges += 15;
   endBalance = accountAmount - 15;
  }
  if (numberOfChecks < 20) {
   System.out.println("Charge for checks: " + ((double)numberOfChecks * 0.1) + "$");
   endBalance -= (double)numberOfChecks * 0.1;
   sumOfCharges += (double)numberOfChecks * 0.1;
  }
 if (numberOfChecks >= 20 && numberOfChecks < 40) {
  System.out.println("Charge for checks: " + ((double)numberOfChecks * 0.08) + "$");
  endBalance -= (double)numberOfChecks * 0.08;
  sumOfCharges += (double)numberOfChecks * 0.08;
 }
 if (numberOfChecks >= 40 && numberOfChecks < 60) {
  System.out.println("Charge for checks: " + (double)numberOfChecks * 0.06 + "$");
  endBalance -= (double)numberOfChecks * 0.06;
  sumOfCharges += (double)numberOfChecks * 0.06;
 }
  if (numberOfChecks >= 60) {
   System.out.println("Charge for checks: " + ((double)numberOfChecks * 0.04) + "$");
   endBalance -= (double)numberOfChecks * 0.04;
   sumOfCharges += (double)numberOfChecks * 0.04;
  }
  System.out.println();
  System.out.println("Bank charge $10 per month.");
  sumOfCharges += 10;
  System.out.println("Sum of all bank fees is: " + sumOfCharges + "$");
 }
}
Comments