In: Computer Science
/**
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 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
System.out.printf("The sum of the fees of %d accounts is $%,.2f\n",
numAccounts, totalFeesAllAccounts);
}//end main
/**
Write a method here that accepts the number of accounts and the sum
of the fees of all the accounts.
This method rather than main should print the message that displays
these values.
*/
}//end class
/**
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 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
displayMessage(numAccounts,totalFeesAllAccounts);
}//end main
/**
Write a method here that accepts the number of accounts and the sum
of the fees of all the accounts.
This method rather than main should print the message that displays
these values.
*/
public static void displayMessage(int numAccounts,double
totalFeesAllAccounts){
//Display the sum of the fees of all the accounts
System.out.printf("The sum of the fees of %d accounts is $%,.2f\n",
numAccounts, totalFeesAllAccounts);
}
}//end class