Cannot find symbyl error

publicclass Bank{

Bank ()

{

List Accounts =new LinkedList();

Accounts.add(5000);

Accounts.add(15000);

int size = Accounts.size();

System.out.println(size);

}

publicvoid ShowAccounts (List list)

{

int size = list.size();

System.out.println("THere are :" + size +"elements in the list");

}

int ShowMenu ()

{

System.out.println("******************************************************************");

System.out.println("\nPLEASE ENTER YOUR CHOICE:\n\n");

System.out.println("Enter 100 \t To view all the accounts/To search for an account.");

System.out.println("Enter 0 \t To exit the application.");

System.out.println("******************************************************************");

Scanner scan =new Scanner(System.in);

int i=scan.nextInt();

//Creating an object account so I can refer to its methods

Account WAcc =new Account(100,1000);

switch (i)

{

case 100:

ShowAccounts( Accounts );

break;

case 0:

System.exit(1);

break;

}

ShowMenu();

return i;

}

publicstaticvoid main (String args[])

{

Bank FHB =new Bank();

FHB.ShowMenu();

}

Basically I have the code above and when I need to compile it, I get an error

Bank.java:94: cannot find symbol

symbol : variable Accounts

location: class Bank

ShowAccounts( Accounts );

In my logic (which is the logic of a beginner to java), everything is fine. Why is this error?

I am importing

import java.util.Scanner;

import java.util.List;

import java.util.LinkedList;

import java.util.ListIterator;

for the list creation

[2985 byte] By [JavaManda] at [2007-10-3 10:33:56]
# 1

You made Accounts a local variable inside your constructor. If you want it to be seen by the whole class, do this:

public class Bank {

private List Accounts;

public Bank ()

{

Accounts = new LinkedList();

//...

Also, by convention, variable and method names should start with lower case letters.

CaptainMorgan08a at 2007-7-15 5:57:09 > top of Java-index,Developer Tools,Java Compiler...
# 2
Thank you very much!I will apply the advice on method and instance names!
JavaManda at 2007-7-15 5:57:09 > top of Java-index,Developer Tools,Java Compiler...
# 3

Actually I have another problem related to scope:

public class Bank {

public List Accounts = new LinkedList();

I have another class where I would like to create a new account.

The CreateAccount is a method of the Account Class, while the ListofAccounts resides in the Bank Class

class Account{

public int CreateAccount (String AccountName)

{

System.out.println("Creating Account.");

//System.out.println("Your AccountID Will be: " + Accounts.size());

System.out.println("Please Enter Amount of Money to Deposit");

Scanner scan = new Scanner(System.in);

int i=scan.nextInt();

Accounts.add(i);

return 1;

}

I stil get an error

Bank.java:40: cannot find symbol

symbol : variable Accounts

location: class Account

Accounts.add(i);

JavaManda at 2007-7-15 5:57:09 > top of Java-index,Developer Tools,Java Compiler...
# 4
also tried it as FHB.Accounts.add(i)and does not work!
JavaManda at 2007-7-15 5:57:09 > top of Java-index,Developer Tools,Java Compiler...
# 5

Account is a variable in the Bank class. Since you made it public, you can access it like this:

yourBankObject.Accounts.add(i);

What I would recomment, however; is that you make Accounts private and add a method into the bank class that will allow you to add to Accounts. For example:

//This is in the Bank class

public void addToAccount(int num)

{

Accounts.add(num);

}

Then, in your Account class, you could do this:

yourBankObject.addToAccount(i);

CaptainMorgan08a at 2007-7-15 5:57:09 > top of Java-index,Developer Tools,Java Compiler...
# 6
Thanks Again!I just realised this topic should probably moved to New to Java. I hope an Admin can do it!CaptainMorgan08 thank you for the support!
JavaManda at 2007-7-15 5:57:09 > top of Java-index,Developer Tools,Java Compiler...