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.


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

Results 1 to 2 of 2

Thread: Bank Balance - while loop

  1. #1
    Join Date
    Oct 2011
    My Mood
    Thanked 0 Times in 0 Posts

    Default Bank Balance - while loop

    // Practical 8 - Q7
    // Marcus Ward
    // 07/11/2011
    /* Program to allow user to enter amount they wish to deposit.
    Program will continue until user says 'No'. They current bank balance is €500.00 */
    import java.util.Scanner;
    public class BankBalanceLoop
       public static void main(String[] args)
    	Scanner keyboardIn = new Scanner(System.in);
    	double balance = 500.00, newBalance, finalBalance, deposit; // declare variables
       char response = Y;
    	while (response == 'Y')
    	   System.out.println("Please enter the amount of your deposit: "); // get user input(to be repeated)
    	   deposit = keyboardIn.nextDouble();
    		System.out.println("Your new balance is" + newBalance);
    		newBalance = keyboardIn.nextDouble();
          System.out.println("Do you want to make another balance ( Y or N)?");
    		response = keyboardIn.next().charAt(0);
    	finalBalance = balance + deposit;
    	System.out.println("Your final balance is" + finalBalance);
            finalBalance = keyboardIn.nextDouble();
    BankBalanceLoop.java:16: cannot find symbol
    symbol : variable Y
    location: class BankBalanceLoop
    char response = Y;
    Last edited by JavaPF; November 9th, 2011 at 07:12 AM. Reason: Use highlight tags!

  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    United Kingdom
    My Mood
    Thanked 287 Times in 225 Posts
    Blog Entries

    Default Re: Bank Balance - while loop

    There are a few issues in your code.

    You need to initialize variables newBalance & deposit

    and char response = Y; should be char response = 'Y'; to get rid of this error although there are still issues here.

    In future, please put the highlight tags around your code and give an actual description of your problems.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. The Following User Says Thank You to JavaPF For This Useful Post:

    mwardjava92 (November 9th, 2011)

Similar Threads

  1. Bank Account HELP!!!! PLEASE.
    By metaleddie13 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 16th, 2011, 08:06 PM
  2. Savings account balance comparison code.
    By Rhyssa6 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 10th, 2011, 06:57 AM
  3. help! Atm bank machine problem
    By galva in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 6th, 2011, 11:08 AM
  4. How to set initial balance of savings account?
    By Punky0214 in forum Java Theory & Questions
    Replies: 0
    Last Post: November 17th, 2010, 09:00 PM
  5. Bank account GUI using swing
    By AlanM595 in forum AWT / Java Swing
    Replies: 5
    Last Post: April 2nd, 2009, 04:39 AM