Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

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

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

    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);
    }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,485
    My Mood
    Mellow
    Thanks
    152
    Thanked 610 Times in 597 Posts

    Default 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.

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HW problem. Trying to finish up the coding for this assignment

    OK. Thanks, and sorry about that.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,485
    My Mood
    Mellow
    Thanks
    152
    Thanked 610 Times in 597 Posts

    Default 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.

  5. #5
    Junior Member
    Join Date
    Feb 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,485
    My Mood
    Mellow
    Thanks
    152
    Thanked 610 Times in 597 Posts

    Default Re: HW problem. Trying to finish up the coding for this assignment

    Set the checkFee based on the number of checks:
    if ( checks >= 60 )
    {
        checkFee = fee4;
    }
    else if ( checks >= 40 )
    {
        checkFee =  fee3;
    }
    // etc. . .
    Then compute the total fee as 10 + checkFee * checks

  7. #7
    Junior Member
    Join Date
    Feb 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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:

    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);
    }
    }

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,485
    My Mood
    Mellow
    Thanks
    152
    Thanked 610 Times in 597 Posts

    Default 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.

  9. #9
    Junior Member
    Join Date
    Feb 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HW problem. Trying to finish up the coding for this assignment

    OK! Thanks so much GregBrannon, your a godsend!!

  10. #10
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,485
    My Mood
    Mellow
    Thanks
    152
    Thanked 610 Times in 597 Posts

    Default Re: HW problem. Trying to finish up the coding for this assignment

    You're welcome.

    Keep coding.

Similar Threads

  1. Help with Coding School Assignment
    By mattmattmatt in forum Loops & Control Statements
    Replies: 12
    Last Post: October 8th, 2013, 09:11 PM
  2. hangman problem java coding
    By angelshark in forum What's Wrong With My Code?
    Replies: 9
    Last Post: January 8th, 2013, 11:55 AM
  3. Help with Java coding problem!
    By eyesackery in forum Java Theory & Questions
    Replies: 4
    Last Post: June 4th, 2012, 08:21 AM
  4. Coding Problem
    By BohmfalkCW in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 26th, 2012, 05:10 PM
  5. Replies: 2
    Last Post: February 19th, 2012, 06:36 AM