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 3 of 3

Thread: Having a programming issue with an assignment

  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Having a programming issue with an assignment

    Can anyone help?
    I am supposed to be building a program that can calculate the fee of a customer and every time I run the program it always comes up with $10 for the fee no matter what. Can anyone see where I am going wrong?

    import java.util.Scanner;

    public class Bankfee
    {
    public static void main(String[] args)
    {
    double checks =0,
    totalfee =0,
    fee = 10,
    fee1 =.1,
    fee2 = .08,
    fee3 = .06,
    fee4 = .04,
    checkFee=0;

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

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

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Having a programming issue with an assignment

    Can you copy the contents of the console and paste it here so we can see the input to the program and its output?

    What are the values of checks and checkFee when totalfee is computed? Add a print statement just before the line where they are used that prints out the values.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: Having a programming issue with an assignment

    You have assigned 0 to checks, so checks is always 0. You should use input instead of checks.
    input = keyboard.nextLine();
     
    if (input < 0) // negative is false
    {
    System.out.print("ERROR: You cannot enter a negative amount!");
    }

    Change all the checks to input.
    Whatever you are, be a good one

Similar Threads

  1. Java Programming (Object Oriented Programming) Assignment
    By azmilPhenom in forum Object Oriented Programming
    Replies: 3
    Last Post: December 21st, 2013, 07:26 AM
  2. Help with programming assignment! New!
    By thejewishpriest in forum Member Introductions
    Replies: 1
    Last Post: April 15th, 2013, 03:30 AM
  3. Beginner assignment - constructor issue / error
    By Jarruda in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 21st, 2012, 01:29 AM
  4. School Assignment; Issue with lookUp method
    By Zero_Starlight in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 21st, 2012, 07:58 PM
  5. Help on programming assignment
    By aaronmcohen in forum AWT / Java Swing
    Replies: 0
    Last Post: March 7th, 2012, 07:47 PM

Tags for this Thread