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

Thread: I need help figuring out why my code won't work

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

    Default I need help figuring out why my code won't work

    Here is the assignment
    Write a program to prepare the monthly charge account statement for a customer of CS CARD International, a credit card company. The program should take as input the previous balance on the account and the total amount of additional charges during the month. The program should then compute the interest for the month, the total new balance (the previous balance plus additional charges plus interest), and the minimum payment due. Assume the interest is 0 if the previous balance was 0 but if the previous balance was greater than 0 the interest is 2% of the total owed (previous balance plus additional charges). Assume the minimum payment is as follows:

    new balance for a new balance less than $50
    $50.00 for a new balance between $50 and $300 (incl)
    20% of new bal for a new balance over $300

    So if the new balance is $38.00, then the person must pay the whole $38.00; if the balance is $128 then the person must pay $50; if the balance is $350 the minimum payment is $70 (20% of 350). The program should print the charge account statement in the format below. Print the actual dollar amounts in each place using currency format from the NumberFormat class.

    This is what I have so far

    import java.util.Scanner;
    import java.text.NumberFormat;

    public class Main
    {
    public static void main(String[] args) {
    NumberFormat money = NumberFormat.getCurrencyInstance();
    double Interest = .02;


    System.out.println("CS CARD International Statement");
    System.out.println("============================== =");

    Scanner myObj = new Scanner(System.in);
    System.out.println("Enter Previous Balance");

    Scanner myObj1 = new Scanner(System.in);
    System.out.println("Enter Additional Charges"); //Get the previous balance and additional charges

    double PreviousBalance = myObj.nextDouble();
    System.out.println("Previous Balance:" + money.format(PreviousBalance));

    double AdditionalCharges = myObj1.nextDouble();
    System.out.println("Additional Charges:" + money.format(AdditionalCharges)); //Read and display the previous balacne and additional charges

    if (PreviousBalance > 0){
    double TotalInterest = (PreviousBalance + AdditionalCharges)*Interest; //Calculate Interest
    System.out.println("Interest:" + money.format(TotalInterest)); //Display Interest
    } else {
    System.out.println("Interest:" + "$" + "0");
    }

    double NewBalance = PreviousBalance + AdditionalCharges + TotalInterest; //Calculate New Balance
    System.out.println("New Balance:" + money.format(NewBalance)); //Display New Balance

    double lazy = NewBalance*.2; // This is only used if New balance is over $300

    double MinimumPayment; //Calculate min payment
    if (NewBalance < 50) {
    System.out.println("Minimum Payment:" + money.format(NewBalance));
    } else if (NewBalance > 50 && NewBalance <= 300) {
    System.out.println("Minimum Payment:" + "$" + "50");
    } else {
    System.out.println("Minimum Payment:" + money.format(lazy) + money.format(NewBalance));
    }


    }
    }


    The error I get says that it can't find symbol TotalInterest even though it's already been declared can someone help me figure out why this is happening please and thank you!?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need help figuring out why my code won't work

    error I get says that it can't find symbol TotalInterest
    The compiler can not find a definition for that variable that is in scope where it is being used. In scope means within the same enclosing {}s.
    Make sure you declare the variable so that it is in scope everywhere you want to use it.


    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.

Similar Threads

  1. Replies: 6
    Last Post: August 5th, 2014, 11:19 AM
  2. Why does this code now work?
    By Tuidog in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 6th, 2014, 08:06 AM
  3. Need help figuring out this code
    By sfsb6 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: January 22nd, 2013, 04:20 PM
  4. need some help figuring out what some code does
    By needshelp in forum Other Programming Languages
    Replies: 2
    Last Post: December 9th, 2012, 05:38 PM
  5. Having a hard time figuring out how to make my code work
    By iainnitro in forum Loops & Control Statements
    Replies: 2
    Last Post: September 6th, 2011, 07:48 AM