# HW problem. Trying to finish up the coding for this assignment

• February 11th, 2014, 03:05 PM
hodnee
HW problem. Trying to finish up the coding for this assignment
Hi,
I have gotten all of the errors out of my coding as of now. The problem is, I am trying to figure out how to setup the very end of it to display the fees. Here is my code as of now as well as the question:

A bank charges a base fee of \$10 per month, plus the following check fees for a commercial checking account:
\$.10 each for less than 20 checks
\$.08 each for 20-39 checks
\$.06 each for 40-59 checks
\$.04 each for 60 or more checks

Write a program that asks for the number of checks written for the month. The programs should then calculate and display the bank's service fees for the month.

Code Java:

```import java.util.Scanner; // scanner class   public class PROB3_CHAL15 { public static void main(String[] args) { String input; char pack; double checks =0, totalfee =0, fee = 10, fee1 =.1, fee2 = .08, fee3 = .06, fee4 = .04, first =0, second =0, third =0, fourth =0; Scanner keyboard = new Scanner(System.in);   int number; System.out.println("Please enter the number of checks you wrote for the past month"); input = keyboard.nextLine(); pack = input.charAt(0);   if (checks < 0) // negative is false { System.out.print("ERROR: You cannot enter a negative amount!"); }   if(checks <20) first = (checks * fee1); if(checks >= 20 && checks <= 39) second = (19*fee1) + ((checks-19) * fee2); if(checks >= 40 && checks <= 59) third = (19*fee1) + (20 * fee2)+((checks-39) * fee3); if(checks >= 60) fourth =(19*fee1) + (20 * fee2)+(20 * fee3)+((checks-59) * fee4);   //adds all fees totalfee = (fee+first+second+third+fourth);   //if closing true(because user didn\'t enter negative number, show total fees System.out.print("Your total monthly Bank Fees are \$" + totalfee); } }```
• February 11th, 2014, 03:22 PM
GregBrannon
Re: HW problem. Trying to finish up the coding for this assignment
Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for newcomers.
• February 11th, 2014, 04:00 PM
hodnee
Re: HW problem. Trying to finish up the coding for this assignment
OK. Thanks, and sorry about that.
• February 11th, 2014, 04:34 PM
GregBrannon
Re: HW problem. Trying to finish up the coding for this assignment
Thanks for fixing.

Are you sure that the total fee is a sum of each block of checks times that block's fee? I interpret the fee as being \$10 plus a single rate * the total number of checks written. For example, if 57 check were written, then the fee would be:

10 + 0.06 * 57

I could be wrong, but that's how I read it.
• February 11th, 2014, 04:38 PM
hodnee
Re: HW problem. Trying to finish up the coding for this assignment
Yea your correct on that. The problem is I cannot figure how to transfer this into code :(
• February 11th, 2014, 04:57 PM
GregBrannon
Re: HW problem. Trying to finish up the coding for this assignment
Set the checkFee based on the number of checks:
Code java:

```if ( checks >= 60 ) { checkFee = fee4; } else if ( checks >= 40 ) { checkFee = fee3; } // etc. . .```
Then compute the total fee as 10 + checkFee * checks
• February 11th, 2014, 05:27 PM
hodnee
Re: HW problem. Trying to finish up the coding for this assignment
Yea I updated what I have to what you updated, but keep getting "error: variable checkFee might not have been initialized" on line 37. Heres where I am at now:

Code Java:

```import java.util.Scanner; // scanner class   public class PROB3_CHAL15 { public static void main(String[] args) { double checks =0, totalfee =0, fee = 10, fee1 =.1, fee2 = .08, fee3 = .06, fee4 = .04, checkFee; String input; Scanner keyboard = new Scanner(System.in);   int number; System.out.println("Please enter the number of checks you wrote for the past month"); input = keyboard.nextLine();   if (checks < 0) // negative is false { System.out.print("ERROR: You cannot enter a negative amount!"); }   if(checks >= 60) checkFee =(fee4); else if(checks >= 40) checkFee = (fee3); else if(checks >=20) checkFee = (fee2); else if(checks <20) checkFee = (fee1);   //adds all fees totalfee = (fee + checkFee * checks);   //if closing true(because user didn't enter negative number, show total fees System.out.print("Your total monthly Bank Fees are \$" + totalfee); } }```
• February 11th, 2014, 05:34 PM
GregBrannon
Re: HW problem. Trying to finish up the coding for this assignment
Do you see that you initialized (set to an initial value) all of your other variables but not checkFee? Fix that.
• February 11th, 2014, 06:02 PM
hodnee
Re: HW problem. Trying to finish up the coding for this assignment
OK! Thanks so much GregBrannon, your a godsend!!
• February 12th, 2014, 02:28 AM
GregBrannon
Re: HW problem. Trying to finish up the coding for this assignment
You're welcome.

Keep coding.