Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Bank Charges A bank charges a fee of $10 per month plus the following check fees for a commercial account. .10 cents for less

JAVA

Bank Charges

A bank charges a fee of $10 per month plus the following check fees for a commercial account. .10 cents for less than 20 checks .08 cents for 2039 checks .06 cents for 40 to 59 checks

.04 each for 60 or more checks. Write a program that would ask the number of checks written for the month. The program should then calculate and display the bank's service fee for month.

For e.g. An account with 35 checks written would be charged .10 cents for the first 20 checks ($1.90) + .08 cents for 16 checks ($1.28) for a total of $3.18 for 35 checks.

An additional $20.00 will apply as the base charge.

Plan of Attack

We will solve this problem using the following steps:

Step 1

We need to first assess and declare all needed variables. Upon reviewing the requirements you will realize that the following three variables will suffice

numchecks To receive input for number of checks.

totalfeeforchecks To track charges for check fee

totalfee holds total fee for account.

We will need additional variables to track:

totalbasecharge $20.00

bankfee $10.00.

As with every bank, you can see they are always interested in charging a lot of fee. And we have to write programs to help our banks make ton of money :).

Now that you have decided what variables to declare lets decide on datatype for each. Since we are dealing with dollars and cents it might be good to declare all of them as float or double. For numchecks we can use an integer data type since we will never charge fee for half a check. :)

Step 2

Now we need to receive input for total number of checks for the month. Based on this value we will automatically compute check fees. You will need to import java.utils package and use the Scanner class to read in an integer and save the value in numchecks variable.

Step 3 main processing.

Now we need to calculate the check fee that will be charged based on the following scale

.10 cents for less than 20 checks

.08 cents for 2039 checks

.06 cents for 40 to 59 checks

.04 each for 60 or more checks. For e.g. An account with 35 checks written would be charged .10 cents for the first 20 checks ($1.90) + .08 cents for 16 checks ($1.28) for a total of $3.18 for 35 checks.

What is the best way of computing the total fee. Here is one approach I would recommend:

We take the input value for numchecks and check if the value is more than 20. For all check less than 20 we charge 10 cents and save it in totalfeeforchecks.

if(numchecks < 20) totalfeeforchecks =totalfeeforchecks + (19 * .10);

else Then, we subtract 19 (.10 cents for less than 20 checks) from the numchecks to calculate fee for the remaining.

numchecks = numchecks 19; Then we add fee for next 20 or less checks at .08 cents and add this to the resulting value in

totalfeeforchecks.

//if I have 35 checks as input I need to account for 16 checks at .08 cents so the if condition takes care of the range.

I write an else statement for the following If I have input of 85 checks I need to account for next 20 checks at .08 cents and continue calculating fee for remaining 46 checks.

if(numchecks > 0) && (numchecks <= 20) {

totalfeeforchecks =totalfeeforchecks + (numchecks * .08); //What is the point of adding totalfeeforchecks in the expression twice?

} else {

}

totalfeeforchecks =totalfeeforchecks + (20 * .08); //Then, we substract 20 (.08 cents for 2039 checks) from numchecks to calculate the fee for the remaining.

numchecks numchecks 20;

Then we add fee for next 20 or less checks at .06 cents and add this to the resulting value in totalfeeforchecks.

//if I have 55 checks as input I need to account for 16 checks at .06 cents so the if condition takes care of the range.

I write an else statement for the following If I have input of 85 checks I need to account for next 20 checks at .06 cents and continue calculating fee for remaining 26 checks.

if(numchecks > 0) && (numchecks <= 20) {

totalfeeforchecks =totalfeeforchecks + (numchecks * .06);

} else {

totalfeeforchecks =totalfeeforchecks + (20 * .06);

}

//Then, we substract 20 (.08 cents for 2039 checks) from numchecks to calculate the fee for the remaining.

numchecks numchecks 20;

Then, we substract 20 (.06 cents for 5059 checks) from numchecks to calculate the fee for the remaining at .04 cents.

totalfeeforchecks =totalfeeforchecks + (numchecks * .04;

In a nutshell, your code might look like this.

if ((numChecks >0) && (numChecks <20)) //checks is between 1 and 19 {

checkfee += 0.1f*numChecks;

} elseif(numChecks>20) //checksis>45 {

checkfee += 0.1f*19; numChecks= 19;

if ((numChecks>0)&&(numChecks<20)) checkfee += 0.08f*numChecks;

else {

else {

} }

}

checkfee += 0.08f*20; numChecks=20;

if ((numChecks>0)&&(numChecks<20)) checkfee += 0.06f*numChecks;

checkfee += 0.06f*20; numChecks=20;

if ((numChecks>0)&&(numChecks<20)) checkfee += 0.04f*numChecks;

Step 4

Now lets complete our calculations to add all the fees that the bank would charge. So we will add totalfee = totalfeeforchecks +totalbasecharge + bankfee.

Step 5

Lets show the value to our precious bank customers by spelling out the fee being charged. So please consider formatting your output like this

Welcome to my Bank!

We love charging fees all kinds of Fee. And we love your business So thank you! The more checksyouwritethemoreyousave.Basedoncheckfeeschedule .10centsforlessthan

20 checks :: .08 cents for 2039 checks :: .06 cents for 40 to 59 checks :: .04 each for 60 or more checks.

your charges are as follows: Totalfee =

Total base charge Total bank fee Total fee for checks

Finally, print the following:

= = = Print value of totalfeeforchecks>

n checks charged at 10 cents fee is ###: ncheckschargedat 8centsfeeis###: ncheckschargedat 6centsfeeis###: ncheckschargedat 4centsfeeis###:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

3. How would this philosophy fit in your organization?

Answered: 1 week ago

Question

Complexity of linear search is O ( n ) . Your answer: True False

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago