Help me finish an instance method which references a class variable?
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?
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)
this.account = new CurrentAccount(holderName,accountNumber,
/* 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;
if(Gambler.mostMoney != null)
// Need code here