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 code in Java: 1. Create a method that displays your name in the console....
Write the code in Java: 1. Create a method that displays your name in the console. This method is void and takes no parameters. Make an app that runs the method in response to a button press. 2. Create a version of the method in #1 that takes the text (String) to be displayed as a parameter. Allow the user to enter the text in a dialog box or text field and display that text in the console. Be sure...
Java program Create two classes based on the java code below. One class for the main...
Java program Create two classes based on the java code below. One class for the main method (named InvestmentTest) and the other is an Investment class. The InvestmentTest class has a main method and the Investment class consists of the necessary methods and fields for each investment as described below. 1.The Investment class has the following members: a. At least six private fields (instance variables) to store an Investment name, number of shares, buying price, selling price, and buying commission...
Using eclipse IDE, create a java project and call it applets. Create a package and call...
Using eclipse IDE, create a java project and call it applets. Create a package and call it multimedia. Download an image and save it in package folder. In the package, create a java applet where you load the image. Use the drawImage() method to display the image, scaled to different sizes. Create animation in Java using the image. In the same package folder, download a sound. Include the sound in your applets and make it repeated while the applet executes....
9) Create a java programming where you will enter two numbers and create only one method,...
9) Create a java programming where you will enter two numbers and create only one method, which will return or display addition, substraction, multiplication, division, average and check which number is greater than the other. Everything in one method and call it in main method.
In Java Create a class called "TestZoo" that holds your main method. Write the code in...
In Java Create a class called "TestZoo" that holds your main method. Write the code in main to create a number of instances of the objects. Create a number of animals and assign a cage and a diet to each. Use a string to specify the diet. Create a zoo object and populate it with your animals. Declare the Animal object in zoo as Animal[] animal = new Animal[3] and add the animals into this array. Note that this zoo...
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 programming - please ONLY answer prompts with java code *Inheritance* will be used in code...
JAVA programming - please ONLY answer prompts with java code *Inheritance* will be used in code Classwork A zoo is developing an educational safari game with various animals. You will write classes representing Elephants, Camels, and Moose. Part A Think through common characteristics of animals, and write a class ZooAnimal. ☑ ZooAnimal should have at least two instance variables of different types (protected), representing characteristics that all animals have values for. ☑ It should also have at least two methods...
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....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT