Question

In: Computer Science

/******************************************************************************** * INSTRUCTIONS * * This program calculates the total fee charged for multiple accounts *...

/********************************************************************************
*                            INSTRUCTIONS                                       *
*  This program calculates the total fee charged for multiple accounts          *
*  Fix the errors so the program compiles and can produce the following output  *
*  How many accounts do you have?: 2                                            *
*  Enter number of checks for account 1: 10                                     *
*  Enter number of checks for account 2: 10                                     *
*  The sum of the fees for 2 accounts is $22.00                                   *
*********************************************************************************/

import java.util.Scanner;

public class BankCharges
{
   public static void main(String[] args)
   {      
      //Variable declarations
      int numChecks;
      double perCheckFee;
      double totalFee;
      double totalFeesAllAccounts; //accumulator
      int numAccounts;
            
      //Constant declarations for base fee and per check fees
      final double BASE_FEE = 10.0;
      final double LESS_THAN_20_FEE = 0.10;
      final double TWENTY_TO_THIRTYNINE_FEE = 0.08;
      final double FORTY_TO_FIFTYNINE_FEE = 0.06;
      final double SIXTY_OR_MORE_FEE = 0.04;
          
      // Create a Scanner object for keyboard input.
      Scanner keyboard = new Scanner(System.in);
      
      //Getting the number of accounts
      System.out.print("How many accounts do you have?: ");
      numAccounts = keyboard.nextInt();
      
      //validating number of accounts
      while (numAccounts <= 0)
      {
         System.out.println("There must be at least 1 account. Try again: ");
         numAccounts = keyboard.nextInt();
      }
      
      //Running total loop to calculate fees for multiple accounts
      for(int i = 0; i <= numAccounts; i++)
      {
         // Get the number of checks written.
         System.out.print("Enter number of checks for account " + (i + 1) + ": ");
         numChecks = keyboard.nextInt();
      
         // Determine the appropriate per-check fee.
         if (numChecks < 20)
            perCheckFee = LESS_THAN_20_FEE;
     
         else if (numChecks <= 39)
            perCheckFee = TWENTY_TO_THIRTYNINE_FEE;
      
         else if (numChecks <= 59)
            perCheckFee = FORTY_TO_FIFTYNINE_FEE;
      
         else
            perCheckFee = SIXTY_OR_MORE_FEE;
               
         //Calculate the total fee
         totalFee = BASE_FEE + numChecks * perCheckFee;
      
         //Totaling the fees from multiple accounts
         totalFeesAllAccounts = totalFee;
         
      }//end for loop
         
      //Display the sum of the fees for all of the accounts
      System.out.printf("The sum of the fees for %d accounts is $%,.2f\n", numAccounts, totalFeesAllAccounts);    
   }
}

Solutions

Expert Solution

Please find your solution below and if any doubt comment and do upvote.

CODE:

import java.util.Scanner;

public class BankCharges
{
   public static void main(String[] args)
   {      
      //Variable declarations
      int numChecks;
      double perCheckFee;
      double totalFee;
      double totalFeesAllAccounts = 0; //accumulator
      int numAccounts;
            
      //Constant declarations for base fee and per check fees
      final double BASE_FEE = 10.0;
      final double LESS_THAN_20_FEE = 0.10;
      final double TWENTY_TO_THIRTYNINE_FEE = 0.08;
      final double FORTY_TO_FIFTYNINE_FEE = 0.06;
      final double SIXTY_OR_MORE_FEE = 0.04;
          
      // Create a Scanner object for keyboard input.
      Scanner keyboard = new Scanner(System.in);
      
      //Getting the number of accounts
      System.out.print("How many accounts do you have?: ");
      numAccounts = keyboard.nextInt();
      
      //validating number of accounts
      while (numAccounts <= 0)
      {
         System.out.println("There must be at least 1 account. Try again: ");
         numAccounts = keyboard.nextInt();
      }
      
      //Running total loop to calculate fees for multiple accounts
      for(int i = 0; i <numAccounts; i++)
      {
         // Get the number of checks written.
         System.out.print("Enter number of checks for account " + (i + 1) + ": ");
         numChecks = keyboard.nextInt();
      
         // Determine the appropriate per-check fee.
         if (numChecks < 20)
            perCheckFee = LESS_THAN_20_FEE;
     
         else if (numChecks <= 39)
            perCheckFee = TWENTY_TO_THIRTYNINE_FEE;
      
         else if (numChecks <= 59)
            perCheckFee = FORTY_TO_FIFTYNINE_FEE;
      
         else
            perCheckFee = SIXTY_OR_MORE_FEE;
               
         //Calculate the total fee
         totalFee = BASE_FEE + numChecks * perCheckFee;
      
         //Totaling the fees from multiple accounts
         totalFeesAllAccounts += totalFee;
         
      }//end for loop
         
      //Display the sum of the fees for all of the accounts
      System.out.printf("The sum of the fees for %d accounts is $%,.2f\n", numAccounts, totalFeesAllAccounts);    
   }
}

OUTPUT:


Related Solutions

Please use Phyton to write a program: Write a program that calculates and displays the total...
Please use Phyton to write a program: Write a program that calculates and displays the total bill at a restaurant for a couple that is dining. The program should collect from the couple, cost of each meal, and the percentage of the final cost that they would like to tip. The sales tax in the state where the restaurant exists is 7.5%. Display to the user, line by line: Total Cost of Both Meals Sales Tax in dollars Tip in...
Your task is to write a program in C or C++ that calculates the total amount...
Your task is to write a program in C or C++ that calculates the total amount of money a person has made over the last year. Your program will prompt the user for dollar amounts showing how much the user has made per job. Some users will have had more than one job, make sure your program allows for this. The program will print out the total made (all jobs) and will print out the federal and state taxes based...
USING C PROGRAMMING ***CODE MUST BE MODULARIZED** Instructions: Create a program that will collect multiple receipts...
USING C PROGRAMMING ***CODE MUST BE MODULARIZED** Instructions: Create a program that will collect multiple receipts from multiple classrooms to accumulate total cookie sales.   Once all receipts have been processed, the program must show what classroom is won and the total amount of cookies they sold. The classrooms that are participating are from the:                 2nd Floor: 201, 202, 203, 204, 205, 206, 207, 208                 3rd Floor: 301,302, 303, 304, 305, 306, 307, 308, 309                 4th Floor: 401,...
A. An ethanol railroad tariff is a fee charged for shipments of ethanol on public railroads....
A. An ethanol railroad tariff is a fee charged for shipments of ethanol on public railroads. An agricultural association publishes tariff rates for​ railroad-car shipments of ethanol. Assuming that the standard deviation of such tariff rates is ​$1150​ determine the probability that the mean tariff rate of 400 randomly selected​ railroad-car shipments of ethanol will be within ​$120 of the mean tariff rate of all​ railroad-car shipments of ethanol. Interpret your answer in terms of sampling error. B. There is...
Does the longstanding existence of a custom—in this case, the nominal amount of the fee charged...
Does the longstanding existence of a custom—in this case, the nominal amount of the fee charged by a college for a transcript—mean that it cannot change?
An ethanol railroad tariff is a fee charged for shipments of ethanol on public railroads. An...
An ethanol railroad tariff is a fee charged for shipments of ethanol on public railroads. An agricultural association publishes tariff rates for​ railroad-car shipments of ethanol. Assuming that the standard deviation of such tariff rates is ​$1000​, determine the probability that the mean tariff rate of 450 randomly selected​ railroad-car shipments of ethanol will be within ​$120 of the mean tariff rate of all​ railroad-car shipments of ethanol. Interpret your answer in terms of sampling error.
1) Here is a program in c++ that calculates a speeding ticket, modify the program to...
1) Here is a program in c++ that calculates a speeding ticket, modify the program to double to cost of the ticket in a construction zone. // This project will calculate a speeding ticket between 0 to 150 mph. // 1. Ask for speed. // 2. Input speed of vehicle // 3. Calculate ticket cost (50$ if over 50mph with an additional 5$ for every mph over). // 4. Display cost of ticket. #include<iostream> using namespace std; int main() {...
Program Name: Divisible. Write a program that calculates the number of integers in a range from...
Program Name: Divisible. Write a program that calculates the number of integers in a range from 1 to some user-specified upper bound that are divisible by 3, the sum of those integers, and the number and sum of those integers not divisible by 3. Your program must display meaningful output which includes: the selected upper bound number of integers divisible by 3 sum of integers divisible by 3 number of integers not divisible by 3 sum of integers not divisible...
Write a program that calculates the balance of a savings account at the end of a...
Write a program that calculates the balance of a savings account at the end of a three month period. It should ask the user for the starting balance and the annual interest rate. A loop should then iterate once for every month in the period, performing the following: Ask the user for the total amount deposited into the account during that month. Do not accept negative numbers. This amount should be added to the balance. Ask the user for the...
Write a program that calculates the balance of a savings account at the end of a...
Write a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number of months that have passed since the account was established. A loop should then iterate once for every month, performing the following: Ask the user for the amount deposited into the account during the month. (Do not accept negative numbers.) This amount should be added...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT