In: Computer Science
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
/**
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