Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    trueblue is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default Help me finish an instance method which references a class variable?

    Dear All,
    Please can anyone help complete this checkIfMostMoney() instance method which accesses the mostMoney class variable directly?
    I have written an explanation of the method. I have declared the class variable but wondered if I also had to initialise it in the constructor?
    I thought not as at the construction stage it is unknown which Gambler has the most money in their account.
    The constructor creates a new instance of the Gambler class and via arguments gives it an account name, account number, opening balance, credit limit and pin number.
    In the checkIfMostMoney() instance method how do I reference the receiver of a message and assign it to the class variable mostMoney?
    Also what line of code will make the comparison between the amount of money in the account of the instance of Gambler referenced by mostMoney and that of the amount of money in the account of the receiver?
    Many thanks.


    public class Gambler
    {
    /* class variable */
    private static Gambler mostMoney;


    /* instance variable */
    private CurrentAccount account;


    /**
    * Default constructor for objects of class Gambler
    */
    public Gambler(String holderName,String accountNumber,
    double anAmount, double aLimit, String aPin)
    {
    super();
    this.account = new CurrentAccount(holderName,accountNumber,
    anAmount,aLimit,aPin);
    }


    /* instance method */

    /**
    * If class variable mostMoney is null the receiver of the message
    * should be assigned to it.
    * If class variable mostMoney references an instance of the Gambler
    * class the method should find out the amount of money in that Gambler's
    * account and compare it with the amount of money held in the receiver's
    * account. If the amount in the receiver's account is greater than or equal
    * to the amount in the other Gambler's account the method should set mostMoney
    * to the receiver. Otherwise mostMoney should remain unchanged.
    */

    private void checkIfMostMoney()
    {
    if(Gambler.mostMoney == null)
    {

    // Need code here;

    }
    else
    {
    if(Gambler.mostMoney != null)
    {

    // Need code here

    }
    }
    }
    }

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

    Default

    I'm sure that you don't want just the solution handed to you, but rather would want to know how your current assumptions are not working, right? I suggest that you give us first your attempt a solution as this will show us your current thinking for the problem and will help us figure out just where you need help. Much luck.

    edit: also, when posting code, please use code tags so that your code will retain its formatting and be readable. To do this, highlight your code in the forum's editor window and then hit the "CODE" button.

  3. #3
    trueblue is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    I'm sure that you don't want just the solution handed to you, but rather would want to know how your current assumptions are not working, right? I suggest that you give us first your attempt a solution as this will show us your current thinking for the problem and will help us figure out just where you need help. Much luck.

    edit: also, when posting code, please use code tags so that your code will retain its formatting and be readable. To do this, highlight your code in the forum's editor window and then hit the "CODE" button.
    Hi there,
    Yes I have been playing around with it and this is as far as I got...

    Java Code:
    private void checkIfMostMoney()
       {
          if(GamblingFrog.mostMoney == null)
          {
             GamblingFrog.mostMoney = this.mostMoney;
          }
          else
          {
             if(GamblingFrog.mostMoney != null)
             {
                // ??
             }
          }
       }

  4. #4
    trueblue is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default

    Quote Originally Posted by trueblue View Post
    Hi there,
    Yes I have been playing around with it and this is as far as I got...

    Java Code:
    private void checkIfMostMoney()
       {
          if(GamblingFrog.mostMoney == null)
          {
             GamblingFrog.mostMoney = this.mostMoney;
          }
          else
          {
             if(GamblingFrog.mostMoney != null)
             {
                // ??
             }
          }
       }

    Sorry, GamblingFrog equals Gambler. I changed it as GamblingFrog sounded crazy.

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

    Default

    1) mostMoney is a static variable, so there isn't really a "this.mostMoney"; there's just a GamblingFrog.mostMoney.

    2) It seems that if it equals null, then mostMoney should be set to this (not this.mostMoney).

    3) in your else block, there's no need for an if(... != null) because if it's made it to the else block, then you already know that it isn't null, right?

    4) In the else block try to figure out what needs to be tested based on the what the teacher is asking your to do. Reread the requirements, perhaps a few times, and then try to put some code in there.

    Best of luck.

  6. #6
    trueblue is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    1) mostMoney is a static variable, so there isn't really a "this.mostMoney"; there's just a GamblingFrog.mostMoney.

    2) It seems that if it equals null, then mostMoney should be set to this (not this.mostMoney).

    3) in your else block, there's no need for an if(... != null) because if it's made it to the else block, then you already know that it isn't null, right?

    4) In the else block try to figure out what needs to be tested based on the what the teacher is asking your to do. Reread the requirements, perhaps a few times, and then try to put some code in there.

    Best of luck.
    But if mostMoney is currently null the receiver should be assigned to it, but there seems to be no way of writing a line of code to achieve this assignment and reference the receiver?

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

    Default

    edit: I imagine that the CurrentAccount class has methods to find out how much money is in the account variable of the message receiver (this) and also for the object currently referenced by the mostMoney variable, right? perhaps you need to use this method.

    Also, I have to register a complaint with your teacher in that it bugs me that a method named "checkIfMostMoney" will change class variables. It seems that a method with this name would leave variables alone and return a boolean, and that instead a setXXX method would be used to change internal variables. But I digress with this rant.

  8. #8
    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 trueblue View Post
    But if mostMoney is currently null the receiver should be assigned to it, but there seems to be no way of writing a line of code to achieve this assignment and reference the receiver?
    The receiver is "this". So use this in your statement (instead of "this.mostMoney").

  9. #9
    trueblue is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    The receiver is "this". So use this in your statement (instead of "this.mostMoney").
    OK the following shortened code compiled OK, but the second line of these workspace commands returns a semantic error and I expected it to allocate kermit to mostMoney?

    GamblingFrog kermit = new GamblingFrog("Beckham","000435",1500.0,2000.0,"321 ");
    kermit.checkIfMostMoney();

    Java Code:
    private void checkIfMostMoney()
       {
          if(GamblingFrog.mostMoney == null)
          {
             GamblingFrog.mostMoney = this;
          }
       }

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

    Default

    what's the error message? edit: it worked for me.

    Also, which is the class name at this point, Gambler or GamblingFrog? I'm confused on that last point.
    Last edited by Fubarable; 06-03-2009 at 02:14 AM.

  11. #11
    trueblue is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default

    This is the message

    Semantic error: Message checkIfMostMoney() not understood by class'GamblingFrog'

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

    Default

    Please re-post your whole code.

  13. #13
    trueblue is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Please re-post your whole code.
    OK here goes....

    I have included the GamblingFrog class which I am trying to complete, the Frog class which is the superclass of GamblingFrog, the CurrentAccount class as the constructor generates a new CurrentAccount for each GamblingFrog via the account instant variable, and the Account class which is the superclass of CurrentAccount.
    So far I have created the constructor and two class variables for GamblingFrog successfully but now I need to create the checkIfMostMoney() method.
    The checkIfMostMoney() method has no arguments and returns no value. The
    method should have the following effect:
    • If the class variable mostMoney is currently null the receiver should be
    assigned to it.
    • If mostMoney references an instance of GamblingFrog, the method should
    find the amount of money in that gamblingFrog’s account and compare it with
    the amount of money held in the receiver’s account. If the amount in the
    receiver’s account is greater than or equal to the amount in the other
    gamblingFrog’s account, the method should set mostMoney to the receiver.
    • Otherwise mostMoney should be left unchanged.

    Java Code:
    /**
     * Class GamblingFrog
     * 
     * GamblingFrogs are like Frogs except that they each have an account with
     * a credit facility and can only catch flies by placing and winning bets.
     * A GamblingFrog can only bet an amount less than or equal to the amount it 
     * has available to spend and the balance of its account must be positive
     * before it does so. GamblingFrogs bet on the outcomes of coin tosses:
     * 'Heads' they win, 'tails' they lose. If a GamblingFrog wins a bet, it has 
     * its account credited by the amount bet and catches a fly; if it loses the
     * bet, it has its account debited by the amount bet and if this results in a
     * negative balance, the GamblingFrog releases a fly if it has one.
     * 
     * 
     * 
     */
    
    
    public class GamblingFrog extends Frog
    {
        /* class variables */
        private static GamblingFrog mostMoney;
        private static GamblingFrog mostFlies;
        
        /* instance variables */
        private CurrentAccount account;
        private boolean hasJustWonBet;
        
        
    
       /**
        * Default constructor for objects of class GamblingFrog
        */
       public GamblingFrog(String holderName,String accountNumber, 
                          double anAmount, double aLimit, String aPin)
       {
          super();
          this.account = new CurrentAccount(holderName,accountNumber, 
                          anAmount,aLimit,aPin);
          this.hasJustWonBet = false;
       }      
      
       
       /* instance methods */       
    
       /**
        * 
        */
       private void checkIfMostMoney()
       {
          if(GamblingFrog.mostMoney == null)
          {
             GamblingFrog.mostMoney = this;
          }
          else
          {
             //if( test ) 
             //{
                // missing code
             //}
          }
       }
       
       /**
        * 
        */
       private void checkIfMostFlies()
       {
          if(GamblingFrog.mostFlies == null)
          {
             
          }
          else
          {
             if(GamblingFrog.mostFlies != null)
             {
                
             }
          }
          
       
       }
       
       /**
        * Returns the receiver's account
        */
       private CurrentAccount getAccount()
       {
          return this.account;
       }
    
       /**
        * Sets the receiver's account to anAccount
        */
       private void setAccount(CurrentAccount anAccount)
       {
          this.account = anAccount;
       }
    
       /**
        * Returns the value of the receiver's hasJustWonBet
        */
       public boolean getHasJustWonBet()
       {
          return this.hasJustWonBet;
       }
    
       /**
        * Sets the receiver's hasJustWonBet to aBool
        */
       public void setHasJustWonBet(boolean bool)
       {
          this.hasJustWonBet = bool;
       } 
       
    }
    Java Code:
    /**
     * Objects of the Frog class are simple software representations of frogs.
     * The class models them as having the attributes position and colour, and
     * hence instance variables of those names.
     * 
     * The protocol provides messages to set the instance variables and to
     * cause changes in an appropriate user interface. Incrementing and
     * decrementing a frog's position by a whole number is reflected in an
     * appropriate user interface as spatial movement to the user's right and
     * left, respectively. (Hence the messages for incrementing and decrementing
     * position are called right() and left().)
     */
    
    public class Frog extends OUAnimatedObject
    {
    /* Instance variables */
    
       private OUColour colour;
       private int position;
       private int flyCount;
       
       /**
        * Constructor for objects of class Frog which initialises colour to green,
        * position to 1 and flyCount to 0.
        */
       public Frog()
       {
          super();
          this.colour = OUColour.GREEN;
          this.position = 1;
          this.flyCount = 0;
       }
    
    /* Instance methods */
    
       /**
        * Returns the position of the receiver.
        */
       public int getPosition()
       {
          return this.position;
       }
       
       /**
        * Sets the position of the receiver to the value of the argument aPosition.
        */
       public void setPosition(int aPosition)
       {
          this.position = aPosition;
          this.update("position");
       }
       
       /**
        * Sets the colour of the receiver to the argument's colour.
        */
       public void sameColourAs (Frog aFrog)
       {
          this.setColour(aFrog.getColour());
       }
    
       /**
        * Returns the colour of the receiver.
        */
       public OUColour getColour()
       {
          return this.colour;
       }
       
       /**
        * Sets the colour of the receiver to the value of the argument aColour.
        */
       public void setColour(OUColour aColour)
       {
          this.colour = aColour;
          this.update("colour");
       }
       
       /**
        * Sets the colour of the receiver to brown.
        */
       public void brown()
       {
          this.setColour(OUColour.BROWN);
       }
       
       /**
        * Sets the colour of the receiver to green.
        */
       public void green()
       {
          this.setColour(OUColour.GREEN);
       }
    
    
      
       /**
        * Causes user interface to emit a sound.
        */
       public void croak()
       {
          this.performAction("croak");
       }
       
       /**
        * Resets the receiver to its "home" position of 1.
        */
       public void home()
       {
          this.setPosition(1);
       }
       
       /**
        * Decrements the position of the receiver by 1.
        */
       public void left()
       {
          this.setPosition(this.getPosition()-1);
       }
       
       /**
        * Increments the position of the receiver by 1.
        */
       public void right()
       {
          this.setPosition(this.getPosition()+1);
       }
    
       /**
        * Causes a change in an appropriate observing user interface.
        * Icon representing the receiver performs a jump animation
        */
       public void jump()
       {
          this.performAction("jump");
       }
       
       /**
        * Returns a string representation of the receiver.
        */
       public String toString()
       {
          return "An instance of class "+ this.getClass().getName() 
                 +  ": position " + this.getPosition() 
                 + ", colour " + this.getColour();
       }
    
       /**
        * Sets the flyCount of the receiver to the value of the argument aFlyCount.
        */
       private void setFlyCount(int aFlyCount)
       {
          this.flyCount = aFlyCount;
       }
       
       /**
        * Returns the flyCount of the receiver.
        */
       public int getFlyCount() 
       {
          return this.flyCount;
       }
       
       /** 
        * Causes the receiver to jump, then croak, then move right and then to
        * increment flyCount.
        */
       public void catchFly()
       {
          this.jump();
          this.croak();
          this.right();
          this.setFlyCount(this.getFlyCount() + 1);
       }   
    
       /** 
        * If flyCount > 0, causes the receiver to jump, then croak, then move
        * left, and then decrement flyCount.
        */
       public void releaseFly()
       {
          if (this.getFlyCount() > 0)
          {
              this.jump();
              this.croak();
              this.left();
              this.setFlyCount(this.getFlyCount() - 1);      
          }
       }
       
       /**
        * Returns the string "The position is " concatenated with
        * the value of the position of the receiver.
        */
       public String positionReport()
       {
          return ("The position is " + this.getPosition());   
       }
       
       /**
        * Cause the receiver to move right then return the string
        * "The position is " concatenated with the value of
        * the receiver's position.
        */
       public String moveRightAndReport()
       {
          this.right();
          return "The position is " + this.getPosition();
       }
    }
    Java Code:
    /**
     * CurrentAccount class used to model simple current accounts, allowing money 
     * to be credited to, and debited and transfered from, an account, subject to 
     * a given credit limit. 
     */
    
    public class CurrentAccount extends Account
    {
       /* instance variables */
       
       private double creditLimit;
       private String pinNo;
       
       /**
        * Constructor for objects of class CurrentAccount
        */    
       public CurrentAccount()
       {
          super();
          this.creditLimit = 0.0;
          this.pinNo = "0000";
       }
       
       /**
        * Constructor for objects of class CurrentAccount, which 
        * sets the values of holder, number, balance, creditLimit 
        * and pinNo to the arguments holderName, accountNumber, 
        * anAmount, aLimit and aPin respectively
        */
       public CurrentAccount(String holderName, String accountNumber, 
                          double anAmount, double aLimit, String aPin)
       {
         super(holderName, accountNumber, anAmount);
         this.creditLimit = aLimit;
         this.pinNo = aPin;
       } 
       
       /* instance methods */
        
       /**
        * Returns the creditLimit of the receiver 
        */   
       private double getCreditLimit()
       {
          return this.creditLimit;
       }
       
       /**
        * Sets the creditLimit of the receiver to the argument aLimit
        */   
       private void setCreditLimit(double aLimit)
       {
          this.creditLimit = aLimit;
       }
    
       /**
        *  Returns the pinNo of the receiver 
        */
       private String getPinNo()    
       {
          return this.pinNo;
       }
    
       /**
        *  Sets the pinNo of the receiver to the argument aPin
        */
       private void setPinNo(String aPin)
       {
           this.pinNo = aPin;
       }
       
       /** 
        * Calculate and return the amount available to spend 
        * (the total of the balance and the creditLimit)
        */
       public double availableToSpend()
       {
            return(this.getBalance() + this.getCreditLimit());
       }
       
       /**
        * If the amount available to spend (the balance and the creditLimit)
        * is greater than or equal to the argument anAmount, the balance of 
        * the receiver is debited by anAmount and the method returns true.
        * If the amount available to spend is less than the argument anAmount, 
        * the method simply returns false.
        */
       public boolean debit(double anAmount)
       {
          if (anAmount <= this.availableToSpend())
          {
             this.setBalance(this.getBalance() - anAmount);
             return true;
          }
          else
          {
             return false;
          }
       }
       
       /**
        * Return true if the pinNo of the receiver matches 
        * the argument aPin, false otherwise.
        */
       private boolean checkPin(String aPin)
       {
          return this.getPinNo().equals(aPin);
       }
       
       /**
        * Prints to the Display Pane the name, number and balance of the receiver.
        */
       public void displayDetails()
       {
          System.out.println("Name: " + this.getHolder());
          System.out.println("Account No: " + this.getNumber());
          System.out.println("Balance: " + this.getBalance()); 
       }
       
       /** 
        * Returns true if receiver is equivalent to (has the same 
        * state as) the argument anAccount, false otherwise 
        */
       private boolean equals(CurrentAccount anAccount)
       {
          return super.equals(anAccount) 
             && this.getCreditLimit() == anAccount.getCreditLimit() 
             && this.getPinNo().equals(anAccount.getPinNo());
       }
    }
    Java Code:
    /**
     * Account class used to model simple bank accounts, allowing money 
     * to be credited to, and debited and transfered from, an account.
     */
    
    public class Account
    {
    /* instance variables */
    
       private String holder;
       private String number;
       private double balance;
    
       /**
        * Constructor for objects of class Account
        */
       public Account()
       {
          super();   // optional
          this.holder = "";
          this.number = "";
          this.balance = 0.0;
       }
    
       /**
        * Constructor for objects of class Account which sets the values of the 
        * holder, number and balance of the receiver to the arguments 
        * holderName, accountNumber and anAmount respectively.
        */
       public Account (String holderName, String accountNumber, double anAmount)
       {
          super(); // optional
          this.holder = holderName;
          this.number = accountNumber;
          this.balance = anAmount;
       }
    
       /* instance methods */
    
       /**
        * Returns the balance of the receiver
        */
       public double getBalance()
       {
          return this.balance;
       }
    
       /**
        * Set the balance of the receiver to the value of the argument anAmount
        */
       public void setBalance(double anAmount)
       {
          this.balance = anAmount;
       }
    
       /**
        * Returns the holder of the receiver
        */
       public String getHolder()
       {
          return this.holder;
       }
    
       /**
        * Returns the number of the receiver
        */
       public String getNumber()
       {
          return this.number;
       }
    
       /**
        * Set the number of the receiver to the value of the argument accountNumber
        */
       public void setNumber(String accountNumber)
       {
          this.number = accountNumber;
       }
    
       /**
        * Set the holder of the receiver to the value of the argument accountHolder
        */
       public void setHolder(String accountHolder)
       {
          this.holder = accountHolder;
       }
    
       /**
        * Credits the receiver with the value of the argument anAmount
        */
       public void credit(double anAmount)
       {
          this.setBalance(this.getBalance() + anAmount);
       }
    
       /**
        * If the balance of the receiver is equal to or greater than the argument anAmount,
        * the balance of the receiver is debited by the argument anAmount and the method
        * returns true.
        *
        * If the balance of the receiver is not equal to or greater than the argument
        * anAmount, the method simply returns false.
        */
       public boolean debit(double anAmount)
       {
          if (this.getBalance() >= anAmount)
          {
             this.setBalance(this.getBalance() - anAmount);
             return true;
          }
          else
          {
             return false;
          }
       }
    
       /**
        * If the balance of the receiver is equal to or greater than the argument anAmount,
        * the balance of the receiver is debited by the argument anAmount. The argument
        * anAccount is then credited by the argument anAmount and the method returns true.
        *
        * If the balance of the receiver is not equal to or greater than the argument
        * anAmount, the method simply returns false.
        */
       public boolean transfer(Account toAccount, double anAmount)
       {
          if (this.debit(anAmount))
          {
             toAccount.credit(anAmount);
             return true;
          }
          else
          {
             return false;
          }
       }
       
       /** 
        * Returns true if receiver is equivalent to (has the same 
        * state as) the argument anAccount, false otherwise 
        */
       public boolean equals(Account anAccount)
       {
          return this.getBalance() == anAccount.getBalance() 
             && this.getNumber().equals(anAccount.getNumber()) 
             && this.getHolder().equals(anAccount.getHolder());
       }
    }

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

    Default

    Where's your main method?

    For instance, if I add this main method to GamblingFrog
    Java Code:
      public static void main(String[] args)
      {
    
        GamblingFrog kermit = new GamblingFrog("Beckham", "000435", 1500.0, 2000.0,
          "321 ");
        System.out.println(kermit == GamblingFrog.mostMoney);
        kermit.checkIfMostMoney();
        System.out.println(kermit == GamblingFrog.mostMoney);
      }
    it prints out
    Java Code:
    false
    true
    Last edited by Fubarable; 06-03-2009 at 02:45 AM.

  15. #15
    trueblue is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default

    all the supplied methods are there and there isn't a task to write any more?

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

    Default

    Good, then you've got it solved? congrats.

  17. #17
    trueblue is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Good, then you've got it solved? congrats.
    No I'm still a zillion miles away and the deadline is tomorrow :(

  18. #18
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    Where's your main method?

    For instance, if I add this main method to GamblingFrog
    Java Code:
      public static void main(String[] args)
      {
    
        GamblingFrog kermit = new GamblingFrog("Beckham", "000435", 1500.0, 2000.0,
          "321 ");
        System.out.println(kermit == GamblingFrog.mostMoney);
        kermit.checkIfMostMoney();
        System.out.println(kermit == GamblingFrog.mostMoney);
      }
    it prints out
    Java Code:
    false
    true
    How does that work?
    Looking at the code just provided checkIfMostMoney is private. Not that I've run it, just a quick read through.

  19. #19
    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 Tolls View Post
    How does that work?
    Looking at the code just provided checkIfMostMoney is private. Not that I've run it, just a quick read through.
    Indeed, but I placed my main method in the GamblingFrog class, so it worked. It's impossible to know how the original poster implemented his main method as he's yet to post this despite my request. But I think you are correct, that checkIfMostMoney should be a public method.

  20. #20
    trueblue is offline Member
    Join Date
    Mar 2009
    Posts
    57
    Rep Power
    0

    Default

    checkIfMostMoney has to be private, and all the supplied methods have been posted. Above all I think I'm struggling to get access to the balance value of the GamblingFrog referenced by mostMoney, or any instance of GamblingFrog, as all avenues seem to be blocked. The accessor methods and the instance variables are all private.....

Page 1 of 2 12 LastLast

Similar Threads

  1. create new instance of variable class
    By Fedor in forum New To Java
    Replies: 5
    Last Post: 04-12-2009, 08:13 PM
  2. Array of objects, as an Instance variable
    By blaklite in forum New To Java
    Replies: 2
    Last Post: 03-25-2009, 12:56 AM
  3. Naming a class instance with a variable
    By pikalex88 in forum New To Java
    Replies: 3
    Last Post: 09-30-2008, 06:27 PM
  4. Instance Variable In Servlet
    By javarishi in forum Java Servlet
    Replies: 3
    Last Post: 06-14-2008, 08:28 AM
  5. Instance variable
    By Jack in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 04:00 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
  •