Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 55

Thread: Help?

  1. #21
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

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

    Default

    Quote Originally Posted by wdlax11 View Post
    Java Code:
    int x =1000;
      
         BankAccount myAccount = new BankAccount (x);
         
         deposit(505.22);
         System.out.println(balance);
    Two questions:

    1) where is your program to deposit those 500 bucks?
    2) what balance?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #23
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default

    If you remeber your method should take three parameters of double.
    So tray to provide deposit() with three doubles, not just with one

  4. #24
    wdlax11 is offline Member
    Join Date
    Feb 2011
    Posts
    25
    Rep Power
    0

    Default

    yeah it has to deposit the $500
    and the balance is 1000.

    I declared it at x.
    The programs are in the same folder also.
    Last edited by wdlax11; 02-06-2011 at 08:04 PM.

  5. #25
    wdlax11 is offline Member
    Join Date
    Feb 2011
    Posts
    25
    Rep Power
    0

    Default

    Quote Originally Posted by milovan View Post
    If you remeber your method should take three parameters of double.
    So tray to provide deposit() with three doubles, not just with one
    so your saying
    Java Code:
    deposit(505.22, x, 1000)
    505.22 being the amount deposited
    x being the balance
    1000 being the current balance?

  6. #26
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default

    If you remeber your method deposit() expects to get three doubles and you are giving only one. Instead try with three doubles

  7. #27
    wdlax11 is offline Member
    Join Date
    Feb 2011
    Posts
    25
    Rep Power
    0

    Default

    ^ gives me the error non-static method deposit (double,double,double) cnnot be referenced from a static context.

    however at that point i had my code as
    Java Code:
     BankAccount.deposit(505.22, 101.2, 1000.3);
    If i change it to
    Java Code:
     deposit(505.22, 101.2, 1000.3);
    it just says cannot find symbol method deposit

  8. #28
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default

    you are close...

  9. #29
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default

    you are trying to execute deposit from static main method, for now just declare your deposit static in your class

  10. #30
    wdlax11 is offline Member
    Join Date
    Feb 2011
    Posts
    25
    Rep Power
    0

    Default

    OHH IM SO CLOSE!!!
    Java Code:
      BankAccount myAccount = new BankAccount (x);
         
         myAccount.deposit(505.22, x , 1000);
         System.out.println(myAccount.balance);
    now i need to fix the printing of the balance.
    Last edited by wdlax11; 02-06-2011 at 08:12 PM.

  11. #31
    wdlax11 is offline Member
    Join Date
    Feb 2011
    Posts
    25
    Rep Power
    0

    Default

    It says cannot find symbol ? It's declared in the BankAccount Class.

  12. #32
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default

    not only that. you have to edit all your methods
    are you willing?

  13. #33
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by wdlax11 View Post
    It says cannot find symbol ? It's declared in the BankAccount Class.
    You'll want to post the actual error message and indicate to us which line of code causes the error.

  14. #34
    wdlax11 is offline Member
    Join Date
    Feb 2011
    Posts
    25
    Rep Power
    0

    Default

    Cannot find symbol - variable balance.

    Java Code:
        /**
       * MAIN METHOD
       */
       public static void main(String [ ] args)
       {
         int x =1000;
        
         BankAccount myAccount = new BankAccount (x);
         
         myAccount.deposit(505.22, x , 1000);
    [COLOR="DarkOrange"]     System.out.println(balance)[/COLOR];

  15. #35
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default

    First: you declared balance as local variable in BankAccount constructor and therefore it is not visible from main method.

  16. #36
    wdlax11 is offline Member
    Join Date
    Feb 2011
    Posts
    25
    Rep Power
    0

    Default

    how do i make it non local?

  17. #37
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default

    Java Code:
    double balance;
    String name;
    
    public BankAccount(){
              // double balance;
              // String name; 
    }

  18. #38
    wdlax11 is offline Member
    Join Date
    Feb 2011
    Posts
    25
    Rep Power
    0

    Default

    It's still not working.
    Java Code:
    public class BankAccount
    {
       
        /**
         * Constructor for objects of class BankAccount
         */
        double balance;
          String name;
    
          public BankAccount(int x){
          double balance;
          String name;
            
        }
    I get the same error code

  19. #39
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default

    Ok, you must learn some basics as Fubarale said.

    Your program will not work until you rewrite it.

    I guess that your intention was to have a global varible called balance.

    After you declare it in your class you can't make some local variable with the same name, so this is not going to work:
    Java Code:
    public class BankAccount
    {
       
        /**
         * Constructor for objects of class BankAccount
         */
        double balance;
          String name;
    
          public BankAccount(int x){
          double balance; // this is unnecessary
          String name; // this is unnecessary
    
            
        }
    
        public void deposit(double deposit, double current,double balance)
        {
        
              balance = deposit + current; // you hide your global variable with this one 
    
        }

  20. #40
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default

    In fact all your methods have their local variables named balance and they never change value of global balance

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

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