Page 1 of 2 12 LastLast
Results 1 to 20 of 27
  1. #1
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Error ' Cannot find symbol class UserAccount"

    Why am I getting the error Error ' Cannot find symbol class UserAccount" is the code below? .


    Java Code:
    // Create 10 account objects
    UserAccount[] UserAccountT = new UserAccount [10];
    
    UserAccountT [0]= new UserAccount ();

    The class is below.

    Java Code:
    
    import java.util.*;
    
    class accountAR {
    
    
    
    Scanner input = new Scanner(System.in);
    
    
    // Create an instance of the class account
    
    Account UserAccount = new Account ();
    
    
    // Welcome method to prompt the user to input ID
    public void Welcome () {
    	int p;
    
    System.out.println("Please enter your ID number\n");
    p =input.nextInt();
    
    // If id is incorrect print message or start mainMenu
    if (p > 10) {
    	System.out.println ("Please re-enter your ID number\n");
    
    }	else {
    	mainMenu();}
    
    
    
    }
    
    public void mainMenu(){
        int selection;
    
            System.out.print("Welcome to the Automated Teller Machine!\n");
            System.out.println("Select from the following menu options below:\n");
            System.out.println("========================");
            System.out.println("| [1]  Check Balance   |");
            System.out.println("| [2]  Withdrawal      |");
            System.out.println("| [3]  Deposit         |");
            System.out.println("| [4]  Exit            |");
            System.out.println("========================");
            System.out.print("Please select your option now: ");
            selection =input.nextInt();
    
    switch (selection){
        case 1:
            viewBalance();
            break;
        case 2:
            withdrawFunds();
            break;
        case 3:
            depositFunds();
            break;
        case 4:
            System.out.println("Thank you for using ATM! \n Goodbye! \n");
    }
    }
    
    
    
    
    
    public void viewBalance() {
        int selection1;
        System.out.println("You have selected Balance.\n");
        System.out.println("\t-- Your Current Balance is:$ " + UserAccount.getbalance());
        System.out.println("Return to main menu? \n [1] for YES \n");
        selection1 =input.nextInt();
    
    switch (selection1){
        case 1:
            mainMenu();
            break;
    }
    
    }
    
    //Method to withdraw money
    public void withdrawFunds() {
        int withdrawSelection;
    
        System.out.println("Amount to withdraw: ");
        System.out.println("[1] - $20");
        System.out.println("[2] - $40");
        System.out.println("[3] - $50");
        System.out.println("[4] - $100");
        System.out.println("[5] - MAIN MENU");
        System.out.print("Please select your option now: ");
        withdrawSelection =input.nextInt();
    
    switch (withdrawSelection){
        case 1:
            UserAccount.withdraw(20);
            mainMenu();
            break;
        case 2:
            UserAccount.withdraw(40);
            mainMenu();
            break;
        case 3:
            UserAccount.withdraw(50);
            mainMenu();
            break;
        case 4:
            UserAccount.withdraw(100);
            mainMenu();
            break;
        case 5:
            mainMenu();
            break;
    }
    
    }
    
    // method for choosing how much to deposit
    public void depositFunds(){
        int addSelection;
    
        System.out.println("Amount to deposit: ");
        System.out.println("[1] - $20");
        System.out.println("[2] - $40");
        System.out.println("[3] - $50");
        System.out.println("[4] - $100");
        System.out.println("[5] - MAIN MENU");
        System.out.print("Please select your option now: ");
        addSelection =input.nextInt();
    
        switch (addSelection){
        case 1:
            UserAccount.deposit(20);
            mainMenu();
            break;
        case 2:
            UserAccount.deposit(40);
            mainMenu();
            break;
        case 3:
            UserAccount.deposit(50);
            mainMenu();
            break;
        case 4:
            UserAccount.deposit(100);
            mainMenu();
            break;
        case 5:
            mainMenu();
            break;
    }
    }
    
    
    
    public accountAR () {}
    
    // Start main
    
    public static void main (String [] args){
    
    
    // Create 10 account objects
    UserAccount[] UserAccountT = new UserAccount [10];
    
    UserAccountT [0]= new UserAccount ();
    
    
    // loop to create 10 accounts with balance of 50
    for (int x = 0; x<10;x++)
     {
    UserAccountT [x] = new UserAccount ();
    UserAccountT [x].setId (x);
    UserAccountT [x].setBalance(50);
     }
    
    // Start the welcome message
    
    Welcome ();
    
    
    
    
     }
     }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,015
    Blog Entries
    7
    Rep Power
    20

    Default Re: Error ' Cannot find symbol class UserAccount"

    What is a UserAccount? I guess it's supposed to be a class but the compiler can't find a class definition for a UserAccount.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Re: Error ' Cannot find symbol class UserAccount"

    HI Jos

    In my viewBalance() method in class accounAR I am having issues referencing the getBalance method in accounts so I added Account UserAccount = new Account (); to the instance variable of accountAR.

    Im new to this and obviously doing things wrong. My account class is below.


    Java Code:
    
    import java.util.*;
    
    public class Account {
    
    
    private int id;
    private String name;
    private double balance;
    private int pinNumber;
    private boolean isActive;
    private Date dateCreated = new Date();
    private double annualInterestRate;
    
    
    
    public Account (int a ) {
    
    int id = a;
    String name ;
    double balance;
    int pinNumber = 1386;
    boolean isActive = false;
    Date dateCreated = new Date();
    double annualInterestRate = 4.4;
    
    }
    
    // no agr constructor
    public Account (){};
    
    
    // set the pinNumber
    protected void  setpinNumber (int input) {
    this.pinNumber = input; }
    
    protected void setId (int inputID) {
    	this.id = inputID;}
    
    protected int getpinNumber () {
    return pinNumber;
    }
    
    
    protected boolean testID ( int entry) {
    
    if ( id != entry  ) {
    isActive = true ;
    }
    else
    {
    System.out.println (" Please re-enter your PIN number");
    isActive = false;
    
    }
    return isActive;
    
    }
    
    
    protected int getid () {
    return id;}
    
    
    protected String getname () {
    return name;}
    
    
    protected  void setBalance ( double c) {
    	this.balance = c;}
    
    protected  double getbalance () {
    return balance;}
    
    protected boolean isActive () {
    return isActive;}
    
    protected  void deposit( double amount )
    	{
    		balance += amount;
    	}
    
            public double withdraw( double amount )
    	{
                    // See if amount can be withdrawn
    		if (balance >= amount)
    		{
    			balance -= amount;
                            return amount;
    		}
    		else
                    // Withdrawal not allowed
                            return 0.0;
    	}
    
    	protected void setannualInterestRate( double rate) {
    
     		annualInterestRate = rate ;
    		}
    
    // int for the 12 months of the year
    
    public double m  = 12;
    
     // method to get the monthly interest rate
    
    	protected  double getmonthlyInterestRate() {
    	 return annualInterestRate / m ;
    
    	    	}
    
    protected Date getDate () {
    	return dateCreated ;}
    
    
    
    
    }

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

    Default Re: Error ' Cannot find symbol class UserAccount"

    I am having issues
    If you are getting errors, please copy the full text of the message and post it here.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Error ' Cannot find symbol class UserAccount"

    UserAccount[] UserAccountT = new UserAccount [10];
    UserAccountT [0]= new UserAccount ();

    What class is UserAccount?
    It's not the class you just posted...
    Last edited by Tolls; 01-09-2012 at 03:53 PM.

  6. #6
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Re: Error ' Cannot find symbol class UserAccount"

    I have edited the code to remove UserAccount. I have added an array of Account but I am now getting the error.


    non-static method getbalance() cannot be referenced from a static context
    non-static method withdraw(double) cannot be referenced from a static context
    non-static method withdraw(double) cannot be referenced from a static context
    non-static method withdraw(double) cannot be referenced from a static context
    non-static method withdraw(double) cannot be referenced from a static context
    non-static method deposit(double) cannot be referenced from a static context
    non-static method deposit(double) cannot be referenced from a static context
    non-static method deposit(double) cannot be referenced from a static context
    non-static method deposit(double) cannot be referenced from a static context

    Java Code:
    import java.util.*;
    
    class accountAR {
    
    Account Accounts = new Account();
    
    Scanner input = new Scanner(System.in);
    
    
    // Welcome method to prompt the user to input ID
    public void Welcome () {
    	int p;
    
    System.out.println("Please enter your ID number\n");
    p =input.nextInt();
    
    // If id is incorrect print message or start mainMenu
    if (p > 10) {
    	System.out.println ("Please re-enter your ID number\n");
    
    }	else {
    	mainMenu();}
    
    
    
    }
    
    public void mainMenu(){
        int selection;
    
            System.out.print("Welcome to the Automated Teller Machine!\n");
            System.out.println("Select from the following menu options below:\n");
            System.out.println("========================");
            System.out.println("| [1]  Check Balance   |");
            System.out.println("| [2]  Withdrawal      |");
            System.out.println("| [3]  Deposit         |");
            System.out.println("| [4]  Exit            |");
            System.out.println("========================");
            System.out.print("Please select your option now: ");
            selection =input.nextInt();
    
    switch (selection){
        case 1:
            viewBalance();
            break;
        case 2:
            withdrawFunds();
            break;
        case 3:
            depositFunds();
            break;
        case 4:
            System.out.println("Thank you for using ATM! \n Goodbye! \n");
    }
    }
    
    
    
    
    
    public void viewBalance() {
        int selection1;
        System.out.println("You have selected Balance.\n");
        System.out.println("\t-- Your Current Balance is:$ " + Account.getbalance());
        System.out.println("Return to main menu? \n [1] for YES \n");
        selection1 =input.nextInt();
    
    switch (selection1){
        case 1:
            mainMenu();
            break;
    }
    
    }
    
    //Method to withdraw money
    public void withdrawFunds() {
        int withdrawSelection;
    
        System.out.println("Amount to withdraw: ");
        System.out.println("[1] - $20");
        System.out.println("[2] - $40");
        System.out.println("[3] - $50");
        System.out.println("[4] - $100");
        System.out.println("[5] - MAIN MENU");
        System.out.print("Please select your option now: ");
        withdrawSelection =input.nextInt();
    
    switch (withdrawSelection){
        case 1:
            Account.withdraw(20);
            mainMenu();
            break;
        case 2:
            Account.withdraw(40);
            mainMenu();
            break;
        case 3:
            Account.withdraw(50);
            mainMenu();
            break;
        case 4:
            Account.withdraw(100);
            mainMenu();
            break;
        case 5:
            mainMenu();
            break;
    }
    
    }
    
    // method for choosing how much to deposit
    public void depositFunds(){
        int addSelection;
    
        System.out.println("Amount to deposit: ");
        System.out.println("[1] - $20");
        System.out.println("[2] - $40");
        System.out.println("[3] - $50");
        System.out.println("[4] - $100");
        System.out.println("[5] - MAIN MENU");
        System.out.print("Please select your option now: ");
        addSelection =input.nextInt();
    
        switch (addSelection){
        case 1:
            Account.deposit(20);
            mainMenu();
            break;
        case 2:
            Account.deposit(40);
            mainMenu();
            break;
        case 3:
            Account.deposit(50);
            mainMenu();
            break;
        case 4:
            Account.deposit(100);
            mainMenu();
            break;
        case 5:
            mainMenu();
            break;
    }
    }
    
    
    
    public accountAR () {}
    
    // Start main
    
    public static void main (String [] args){
    
    
    // Create 10 account objects
    Account[] Account = new Account [10];
    
    Account [0]= new Account ();
    
    
    // loop to create 10 accounts with balance of 50
    for (int x = 0; x<10;x++)
     {
    Account [x] = new Account ();
    Account [x].setId (x);
    Account [x].setBalance(50);
     }
    
    // Start the welcome message
    
    
    
    
    
    
     }
     }

  7. #7
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Re: Error ' Cannot find symbol class UserAccount"

    I have got it to work by changing the Account to Accounts. The question I have now is how do I get viewBalance method () to
    show the balance of array Account[0]?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

    Default Re: Error ' Cannot find symbol class UserAccount"

    show the balance of array Account[0]
    Do you mean the contents of the one element at index 0
    or the contents of the whole array?
    For the whole array the Arrays class's toString() method will format the array's contents into a String.

  9. #9
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Re: Error ' Cannot find symbol class UserAccount"

    It would be the balance of one element. The system prompts the user to enter an id.
    If the id is entered incorrectly the user will be asked to enter a correct id. Once the id is accepted the main menu is
    displayed. You can enter a choice 1 for viewing the current balance, 2 for withdrawing money, 3 for depositing money and 4 for exiting the main menu.

    If the user tries to withdraw more money than is available the program reports a “ Not enough funds” message. Once you exit the system will prompt for an id again. So once the system starts, it will not stop.

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

    Default Re: Error ' Cannot find symbol class UserAccount"

    It would be the balance of one element
    Not sure what your problem is. If you have the index to the array, you can use that index to get the element.
    If you have the element then you can get the balance of that element.

    Please explain where your problem is.

  11. #11
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Re: Error ' Cannot find symbol class UserAccount"

    Well the problem I am having is the users input is not showing the balance of the array element just created when mainMenu() called.


    Java Code:
    import java.util.*;
    
    class accountAR {
    
    Account Accounts = new Account();
    
    Scanner input = new Scanner(System.in);
    
    
    // Welcome method to prompt the user to input ID
    public void Welcome () {
    	int p;
    
    System.out.println("Please enter your ID number\n");
    p =input.nextInt();
    
    // If id is incorrect print message or start mainMenu
    if (p > 10) {
    	System.out.println ("Please re-enter your ID number\n");
    
    }	else {
    	mainMenu();}
    
    
    
    }
    
    public void mainMenu(){
        int selection;
    
            System.out.print("Welcome to the Automated Teller Machine!\n");
            System.out.println("Select from the following menu options below:\n");
            System.out.println("========================");
            System.out.println("| [1]  Check Balance   |");
            System.out.println("| [2]  Withdrawal      |");
            System.out.println("| [3]  Deposit         |");
            System.out.println("| [4]  Exit            |");
            System.out.println("========================");
            System.out.print("Please select your option now: ");
            selection =input.nextInt();
    
    switch (selection){
        case 1:
            viewBalance();
            break;
        case 2:
            withdrawFunds();
            break;
        case 3:
            depositFunds();
            break;
        case 4:
            System.out.println("Thank you for using ATM! \n Goodbye! \n");
    }
    }
    
    
    
    
    
    public void viewBalance() {
        int selection1;
        System.out.println("You have selected Balance.\n");
        System.out.println("\t-- Your Current Balance is:$ " + Accounts.getbalance());
        System.out.println("Return to main menu? \n [1] for YES \n");
        selection1 =input.nextInt();
    
    switch (selection1){
        case 1:
            mainMenu();
            break;
    }
    
    }
    
    //Method to withdraw money
    public void withdrawFunds() {
        int withdrawSelection;
    
        System.out.println("Amount to withdraw: ");
        System.out.println("[1] - $20");
        System.out.println("[2] - $40");
        System.out.println("[3] - $50");
        System.out.println("[4] - $100");
        System.out.println("[5] - MAIN MENU");
        System.out.print("Please select your option now: ");
        withdrawSelection =input.nextInt();
    
    switch (withdrawSelection){
        case 1:
            Accounts.withdraw(20);
            mainMenu();
            break;
        case 2:
            Accounts.withdraw(40);
            mainMenu();
            break;
        case 3:
            Accounts.withdraw(50);
            mainMenu();
            break;
        case 4:
            Accounts.withdraw(100);
            mainMenu();
            break;
        case 5:
            mainMenu();
            break;
    }
    
    }
    
    // method for choosing how much to deposit
    public void depositFunds(){
        int addSelection;
    
        System.out.println("Amount to deposit: ");
        System.out.println("[1] - $20");
        System.out.println("[2] - $40");
        System.out.println("[3] - $50");
        System.out.println("[4] - $100");
        System.out.println("[5] - MAIN MENU");
        System.out.print("Please select your option now: ");
        addSelection =input.nextInt();
    
        switch (addSelection){
        case 1:
            Accounts.deposit(20);
            mainMenu();
            break;
        case 2:
            Accounts.deposit(40);
            mainMenu();
            break;
        case 3:
            Accounts.deposit(50);
            mainMenu();
            break;
        case 4:
            Accounts.deposit(100);
            mainMenu();
            break;
        case 5:
            mainMenu();
            break;
    }
    }
    
    
    
    public accountAR () {}
    
    // Start main
    
    public static void main (String [] args){
    
    	accountAR a = new accountAR ();
    
    Scanner input1 = new Scanner(System.in);
    // Create 10 account objects
    Account[] Account = new Account [10];
    
    Account [0]= new Account ();
    
    
    // loop to create 10 accounts with balance of 50
    for (int x = 0; x<10;x++)
     {
    Account [x] = new Account ();
    Account [x].setId (x);
    Account [x].setBalance(50);
     }
    
    // Start the welcome message
    int p;
    System.out.println("Please enter your ID number\n");
    p =input1.nextInt();
    
    // If id is incorrect print message or start mainMenu
    if (p > Account.length) {
    	System.out.println ("Please re-enter your ID number\n");
    }
    		else {
    			a.mainMenu(); }
    
    
     }
     }

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

    Default Re: Error ' Cannot find symbol class UserAccount"

    the users input is not showing the balance of the array element just created
    Try debugging your code by printing out the user's input when it is first read in and then again when the code that uses that input is trying to access the array element. Is the value the user input being lost?

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: Error ' Cannot find symbol class UserAccount"

    You've got an Account in accountAR which is what is being used by the mainMenu stuff to display balances.
    This has no balance.
    This is not one of the Accounts in the array created in the main() method.

  14. #14
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Re: Error ' Cannot find symbol class UserAccount"

    So this account I have in accountAR is showing the balance? Should I add the array of accounts to accountAR instead of main?

    I tried this before but got an error telling me to add ']' but I had

    Java Code:
    Account[] acc = new Account [10];
    acc [0] = new Account ();
    Last edited by r1b; 01-09-2012 at 06:52 PM.

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

    Default Re: Error ' Cannot find symbol class UserAccount"

    Is account a subclass of Account?
    Case is VERY important.

  16. #16
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Re: Error ' Cannot find symbol class UserAccount"

    Quote Originally Posted by r1b View Post
    So this account I have in accountAR is showing the balance? Should I add the array of accounts to accountAR instead of main?

    I tried this before but got an error telling me to add ']' but I had

    Java Code:
    Account[] acc = new Account [10];
    acc [0] = new Account ();

    Sorry this is what I had entered.

  17. #17
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

    Default Re: Error ' Cannot find symbol class UserAccount"

    If you defined your array of Account objects outside of the main() method, then all the methods in the class could see and use it. You can still assign values to the elements of the array inside the main method.

  18. #18
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Re: Error ' Cannot find symbol class UserAccount"

    I am getting this error now for changing the code to this.

    Java Code:
    import java.util.*;
    
    class accountAR {
    
    
    Account[] Accounts = new Account [10];
    Accounts [0] = new Account();
    Scanner input = new Scanner(System.in);
    ']' expected
    ';' expected
    illegal start of type
    <identifier> expected
    ';' expected
    illegal start of type
    <identifier> expected


    all on line 7 which is Accounts [0] = new Account();

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,602
    Rep Power
    23

    Default Re: Error ' Cannot find symbol class UserAccount"

    Line 7 belongs in a method.

  20. #20
    r1b
    r1b is offline Member
    Join Date
    Jan 2012
    Posts
    31
    Rep Power
    0

    Default Re: Error ' Cannot find symbol class UserAccount"

    sorry could you explain that a little more? Do I create a setAccount method?
    Last edited by r1b; 01-09-2012 at 08:15 PM.

Page 1 of 2 12 LastLast

Similar Threads

  1. "Cannot find symbol" error
    By MBD in forum New To Java
    Replies: 5
    Last Post: 09-27-2011, 02:41 PM
  2. "cannot find symbol" error
    By droidus in forum New To Java
    Replies: 2
    Last Post: 09-07-2011, 07:43 AM
  3. Replies: 5
    Last Post: 04-24-2011, 03:21 PM
  4. Error "can not find symbol variable"
    By FullMetalHollow in forum New To Java
    Replies: 5
    Last Post: 10-04-2009, 09:51 PM
  5. "Cannont find symbol Constructor" error
    By Welsh in forum New To Java
    Replies: 7
    Last Post: 01-25-2008, 12:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •