Question

In: Computer Science

only JAVA code /** Create a method as instructed below and then call it appropriately. */...

only JAVA code

/**
Create a method as instructed below and then call it appropriately.
*/

import java.util.Scanner;

public class MoreBankCharges
{
      //Constant declarations for base fee and per check fees
      //Class scope so constants are accessible by all methods
      static final double BASE_FEE = 10.0;
      static final double LESS_THAN_20_FEE = 0.10;
      static final double TWENTY_TO_THIRTYNINE_FEE = 0.08;
      static final double FORTY_TO_FIFTYNINE_FEE = 0.06;
      static final double SIXTY_OR_MORE_FEE = 0.04;
   
   public static void main(String[] args)
   {      
      //Variable declarations
      int numChecks;
      double perCheckFee;
      double totalFee;
      double totalFeesAllAccounts = 0; //accumulator
      int numAccounts;
                      
      // 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 of all the accounts
      //NOTE: method doesn't return a value so no need to store anything
      displayOutput(numAccounts, totalFeesAllAccounts);
   
   }//end main

   /**
   The displayOutput method displays the number of accounts and the sum of the fees of all the accounts.
   @param numAcct The number of accounts.
   @param sumAllFees The sum of the fees of all the accounts.
   */
   public static void displayOutput(int numAcct, double sumAllFees) 
   {
      System.out.printf("The sum of the fees of %d accounts is $%,.2f\n", numAcct, sumAllFees); 
      
   }//end displayOutput
   
   /**
   Write a method here that accepts the number of checks.
   The method should determine and return the per check fee
   */
   
}//end class

Solutions

Expert Solution

/**
Create a method as instructed below and then call it appropriately.
*/

import java.util.Scanner;

public class MoreBankCharges

{
      //Constant declarations for base fee and per check fees
      //Class scope so constants are accessible by all methods
      static final double BASE_FEE = 10.0;
      static final double LESS_THAN_20_FEE = 0.10;
      static final double TWENTY_TO_THIRTYNINE_FEE = 0.08;
      static final double FORTY_TO_FIFTYNINE_FEE = 0.06;
      static final double SIXTY_OR_MORE_FEE = 0.04;

   public static void main(String[] args)
   {    
      //Variable declarations
      int numChecks;
      double perCheckFee;
      double totalFee;
      double totalFeesAllAccounts = 0; //accumulator
      int numAccounts;
                    
      // 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.
         perCheckFee = calculatePerCheckFee(numChecks);
      
         //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 of all the accounts
      //NOTE: method doesn't return a value so no need to store anything
      displayOutput(numAccounts, totalFeesAllAccounts);

   }//end main

   /**
   The displayOutput method displays the number of accounts and the sum of the fees of all the accounts.
   @param numAcct The number of accounts.
   @param sumAllFees The sum of the fees of all the accounts.
   */
   public static void displayOutput(int numAcct, double sumAllFees)
   {
      System.out.printf("The sum of the fees of %d accounts is $%,.2f\n", numAcct, sumAllFees);
    
   }//end displayOutput

   /**
   Write a method here that accepts the number of checks.
   The method should determine and return the per check fee
   */
    public static double calculatePerCheckFee( int numChecks)
   {
        double checkFee;
        if (numChecks < 20)
            checkFee = LESS_THAN_20_FEE;
   
         else if (numChecks <= 39)
            checkFee = TWENTY_TO_THIRTYNINE_FEE;
    
         else if (numChecks <= 59)
            checkFee = FORTY_TO_FIFTYNINE_FEE;
    
         else
            checkFee = SIXTY_OR_MORE_FEE;
       
        return checkFee;
             
    
   }//end calculatePerCheckFee

}//end class


Related Solutions

/** Create a method as instructed below and then call it appropriately. */ import java.util.Scanner; public...
/** Create a method as instructed below and then call it appropriately. */ 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...
Write the Java source code necessary to build a solution for the problem below: Create a...
Write the Java source code necessary to build a solution for the problem below: Create a MyLinkedList class. Create methods in the class to add an item to the head, tail, or middle of a linked list; remove an item from the head, tail, or middle of a linked list; check the size of the list; and search for an element in the list. Create a test class to use the newly created MyLinkedList class. Add the following names in...
Write the Java source code necessary to build a solution for the problem below: Create a...
Write the Java source code necessary to build a solution for the problem below: Create a MyLinkedList class. Create methods in the class to add an item to the head, tail, or middle of a linked list; remove an item from the head, tail, or middle of a linked list; check the size of the list; and search for an element in the list. Create a test class to use the newly created MyLinkedList class. Add the following names in...
JAVA: Create a circle that contains the following... Sample code to work from provided below. FIELDS:...
JAVA: Create a circle that contains the following... Sample code to work from provided below. FIELDS: a private double that holds the radius. CONSTRUCTORS a no argument constructor that sets the radius to zero a constructor that takes a single argument of type double which is the radius. METHODS a method called "getRadius" which returns the current radius a method called "setRadius" which takes a single parameter of type double containing the new radius a method called "getArea" which returns...
JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include...
JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include additional functions called by the main. Make sure to use ES6 style of keywords => instead of the older function and for local scope variables use the keyword let and not a keyword var. Make sure to follow the requirements and recheck before submitting. PROJECT GOAL: Assume that hot dogs come in packages of 10, and hot dog buns come in packages of 8....
Create a JAVA code program: Huffman code will be converted to its text equivalent Output an...
Create a JAVA code program: Huffman code will be converted to its text equivalent Output an error message if the input cannot be converted I can give an thumbs up! :)
Create a java program that will do the following: Create a method called getInt.Allow the user...
Create a java program that will do the following: Create a method called getInt.Allow the user to enter up to 20 student names,and for each student 3 quiz scores (in the range 0-100). Once input is done, display each student’s name, their three quiz scores, and their quiz score average, one student per line. The output table does not need to line up perfectly in columns.Use dialog boxes for all input and output.Use the method to input the three scores.Parameter...
In Java Create an interface Create an interface Printing, which have a method getPageNumber () that...
In Java Create an interface Create an interface Printing, which have a method getPageNumber () that return page number of any printing. Create an abstract class named Novel that implements Printing. Include a String field for the novel's title and a double field for the novel price. Within the class, include a constructor that requires the novel title, and add two get methods--one that returns the title and one that returns the price. Include an abstract method named setPrice().. Create...
Topic is relates to Java programming! Code using java GUI 2. Create the following controls: a)...
Topic is relates to Java programming! Code using java GUI 2. Create the following controls: a) a TextField b) a Button c) a Text d) a Label 3. create the following container and put them the above controls: a) a VBox controller b) a BorderPane controller c) a GridPane
Question(Design Java Method). There is a java code what created a "Student" class and hold all...
Question(Design Java Method). There is a java code what created a "Student" class and hold all the books owned by the student in the inner class "Book". Please propose a new method for the Student class so that given a Student object "student", a program can find out the title of a book for which student.hasBook(isbn) returns true. Show the method code and the calls to it from a test program. The Student class is following: import java.lang.Integer; import java.util.ArrayList;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT