[Solved] Method of overload


Just like previous question – there is no such variable number when you write acctNum = number; in public FlexibleAccount(String owner):

public FlexibleAccount(String owner)
    {
     balance = 0;
     name=owner;
     Random generator = new Random();
     number=generator.nextDouble();        << number is not declared
     this.acctNum= number;
     }

EDIT:
This is your 2nd constructor:

 public FlexibleAccount(double initBal, String owner, double number)
  {
    Random generator = new Random();
     balance = initBal;
    name = owner;
     number=generator.nextDouble();
     this.acctNum= number;
    }

For some reason you declare it with 3 arguments although you wrote you want it to be receive only 2 arguments –

public FlexibleAccount (double
initBal, String owner) – initializes
the balance and owner as specified;
randomly generates the account number.

I guess you wanted to have the variable number… it should be more something like that:

 public FlexibleAccount(double initBal, String owner)
      {
        Random generator = new Random();
         balance = initBal;
        name = owner;
         this.acctNum= generator.nextLong();
        }

Now as you said in the prev. question this is a homework, so I won’t add to that. Read the answers and comments you got until now and work it up.

3

solved Method of overload