Results 1 to 10 of 10
  1. #1
    Aggy is offline Member
    Join Date
    Jan 2010
    Location
    England
    Posts
    15
    Rep Power
    0

    Default Constructor Problem

    Can you tell me why i am getting the "cannot file symbol - variable CurrentAccount" when i try to compile.?

    /**
    * Default constructor for objects of class CurrentAccountFrog
    */
    public CurrentAccountFrog(String account)
    {
    super();
    CurrentAccount = account;
    }

    any pointers would be appreciated.

    thanks

  2. #2
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    ok so it can be of many reasons

    did you declare CurrentAccount anywhere?

    is the constructor is within its scope?

    did you write it correctly (java is case senstive)

  3. #3
    Aggy is offline Member
    Join Date
    Jan 2010
    Location
    England
    Posts
    15
    Rep Power
    0

    Default

    I have two classes (Frog and Account) and two sub classes (CurrentAccountFrog and CurrentAccount) coming off of the first two classes respectively. What i am trying to do is modify the constructor for the currentaccountfrog class so that it assigns an instance of currentaccount to a variable in currentaccountfrog called account.

  4. #4
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    Quote Originally Posted by Aggy View Post
    I have two classes (Frog and Account) and two sub classes (CurrentAccountFrog and CurrentAccount) coming off of the first two classes respectively. What i am trying to do is modify the constructor for the currentaccountfrog class so that it assigns an instance of currentaccount to a variable in currentaccountfrog called account.
    hmm..i can vaguely get it, but the problem for your error shouldnt be too hard.

    It would really be an asset if you showed us the full code

    P.S is it the 1st time your declaring CurrentAccount?

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    the constructor for the currentaccountfrog class so that it assigns an instance of currentaccount to a variable in currentaccountfrog called account

    Precise capitalisation would help. Also addressing the three questions asked in the first reply.

    Perhaps the intention of the constructor is something like:

    Java Code:
    public class CurrentAccountFrog extends Frog {
        private CurrentAccount account;
    
        public CurrentAccountFrog() {
            // (1)
            account = new CurrentAccount(); // (2)
        }
    }
    Of course (1) the Frog constructor must get invoked. If there is no no-arg constructor then an appropriate one must be called. And (2) similarly for the CurrentAccount constructor: an appropriate one has to be used.

  6. #6
    Aggy is offline Member
    Join Date
    Jan 2010
    Location
    England
    Posts
    15
    Rep Power
    0

    Default

    /**
    * Class CurrentAccountFrog, created for a subclass of Frog
    *
    * @author (***** ******)
    * @version (19/01/2010)
    */
    public class CurrentAccountFrog extends Frog
    {
    /* instance variables */
    private CurrentAccount account;

    /**
    * Default constructor for objects of class CurrentAccountFrog
    */
    public CurrentAccountFrog(String account)
    {
    super();
    account = account;
    }
    /* instance methods */

    /**
    * Returns the account details of the receiver
    */
    public CurrentAccount getAccount()
    {
    return this.account;
    }

    /**
    * Sets the account of the receiver to the argument aAccount
    */
    public void setAccount(CurrentAccount aAccount)
    {
    this.account = aAccount;
    }
    }

  7. #7
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    super() isn't really needed.

    Perhaps the rather random "account=account" should be replaced with

    Java Code:
    this.account = new CurrentAccount(account);

    (assuming there is a CurrentAccount constructor that takes a String argument.)

  8. #8
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    as brock said

    Java Code:
            account = new CurrentAccount();
    should be done it doesnt make sense when you do this
    Java Code:
    public CurrentAccountFrog(String account)
    {
    super();
    account = account;
    }
    either change the name for the paramenter as acc or the private variable because when you do that it considers the account paramenter rather than the private.

    instead you can do this

    Java Code:
    this.account = (account)
    considered both are of the same type or under a similar branch of hierarchy.

  9. #9
    Aggy is offline Member
    Join Date
    Jan 2010
    Location
    England
    Posts
    15
    Rep Power
    0

    Default

    ok, one last problem before i give up completely.

    public CurrentAccountFrog(String holderName, String accountNumber,
    double anAmount, double aLimit, String aPin)
    {
    CurrentAccountFrog = aAccount;
    }

    gives me the error "cannot find symbol - Variable CurrentAccountFrog" even though it is declared on the code above. what the hell is going on with this.

  10. #10
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    What you posted is a constructor: there are no variables declared other than the parameters (holderName, accountNumber and the rest).

    You have introduced two things that the compiler will regard as variables: CurrentAccountFrog (with the strange capital C) and aAccount. Neither are declared anywhere in the code you posted and the compiler will bounce right back with "cannot find symbol". A human would ask (as in the very first reply) "are these declared anywhere? In the same scope as the constructor? Without typos?".

Similar Threads

  1. Problem with using an array in a constructor
    By planesinspace in forum New To Java
    Replies: 3
    Last Post: 08-28-2009, 09:17 AM
  2. [SOLVED] Constructor problem
    By McChill in forum New To Java
    Replies: 3
    Last Post: 03-09-2009, 06:43 PM
  3. Problem with Constructor
    By ToastyBainey in forum New To Java
    Replies: 3
    Last Post: 03-09-2009, 02:36 AM
  4. [SOLVED] Constructor problem
    By sfe23 in forum New To Java
    Replies: 10
    Last Post: 02-21-2009, 08:22 PM
  5. Replies: 0
    Last Post: 12-19-2007, 09:10 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
  •