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: My code is 99%, 1 error I can't fix, can you?

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

    Default My code is 99%, 1 error I can't fix, can you?

    import java.util.Scanner;

    public class BankAccount
    {
    public static void main(String[] args)
    {
    Scanner keyboard = new Scanner(System.in);

    do
    {
    System.out.println("Enter your bank account dollars in whole dollars and cents.");

    double initialBalance = keyboard.nextDouble();

    System.out.println("Enter interest on your bank account as a whole number.");
    System.out.println("For example, a 4.5% interest rate would be entered as \"4.5\":");

    double interestRate = keyboard.nextDouble();
    double yearBalance = initialBalance;
    double monthBalance = initialBalance;
    double dayBalance = initialBalance;
    int year;
    int month;
    int day;
    char answer;

    for (year = 1; year <= 10; year++)
    {
    yearBalance = (yearBalance * (interestRate / 100.0));
    }
    for (month = 1; month <= 120; month++)
    {
    monthBalance = (monthBalance * (interestRate / 1200.0));
    }
    for (day = 1; day <= 3650; day++)
    {
    dayBalance = (dayBalance * (interestRate / 36500.0));
    }
    System.out.println("An initial investment of " + initialBalance + " will become one of the following over ten years.");
    System.out.println("If interest is accrued yearly at " + interestRate + "%, you will have a total of " + yearBalance + ".");
    System.out.println("If interest is accrued monthly at " + interestRate + "%, you will have a total of " + monthBalance + ".");
    System.out.println("If interest is accrued daily at " + interestRate + "%, you will have a total of " + dayBalance + ".");
    System.out.println("Would you like to calculate again using a different balance and/or interest rate? Answer \"Y\" or \"N\":");
    answer = keyboard.nextLine().toUpperCase().charAt(0);

    } while (answer == 'Y');
    }
    }[/B]

    --- Update ---

    the error shows the carrot under the word answer, on the last "while" line


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

    Default Re: My code is 99%, 1 error I can't fix, can you?

    Please copy and paste here the full text of the error messages.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE 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. can anyone help me to fix the error in the program???
    By divi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 25th, 2013, 01:36 AM
  2. can anyone help me to fix the error in the program???
    By divi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 24th, 2013, 02:49 PM
  3. Cant fix this error... Help!
    By Hypermegazord in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 1st, 2012, 01:06 PM
  4. Need Help, Not sure how to fix basic error!
    By ChicoTheMan94 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 15th, 2012, 01:41 PM
  5. Simply error; can't quite fix it.
    By JRabbit in forum Android Development
    Replies: 1
    Last Post: March 19th, 2012, 06:46 PM

Tags for this Thread