java - Method of overload -


  //******************************************************* // flexibleaccount.java // // bank account class methods deposit to, withdraw from, // change name on, , string representation // of account. //******************************************************* import java.util.random; public class flexibleaccount {   private double balance;   private string name;   private long acctnum;    //----------------------------------------------   //constructor -- initializes balance, owner, , account number   //----------------------------------------------   public flexibleaccount(double initbal, string owner, long number)   {     balance = initbal;     name = owner;     acctnum = number;   }    public flexibleaccount(double initbal, string owner, double number)   {     random generator = new random();      balance = initbal;     name = owner;      number=generator.nextdouble();      this.acctnum= number;     }      public flexibleaccount(string owner)     {      balance = 0;      name=owner;      random generator = new random();      number=generator.nextdouble();      this.acctnum= number;      }   //----------------------------------------------   // checks see if balance sufficient withdrawal.   // if so, decrements balance amount; if not, prints message.   //----------------------------------------------   public void withdraw(double amount)   {     if (balance >= amount)        balance -= amount;     else        system.out.println("insufficient funds");   }    public void withdraw(double amount,int fee)    {    if(balance>=amount)     balance-= amount+fee;     else         system.out.println("insufficient funds");     }       //----------------------------------------------   // adds deposit amount balance.   //----------------------------------------------   public void deposit(double amount)   {     balance += amount;   }    //----------------------------------------------   // returns balance.   //----------------------------------------------   public double getbalance()   {     return balance;   }     //----------------------------------------------   // returns string containing name, account number, , balance.   //----------------------------------------------   public string tostring()   {     return "name: " + name +  "\naccount number: " + acctnum + "\nbalance: " + balance;    } } 

this have , i'm trying overload flexibleaccount 3 times follow

  1. public flexibleaccount (double initbal, string owner, long number) – initializes balance, owner, , account number specified
  2. public flexibleaccount (double initbal, string owner) – initializes balance , owner specified; randomly generates account number.
  3. public flexibleaccount (string owner) – initializes owner specified; sets initial balance 0 , randomly generates account number.

when compiled these error

 flexibleaccount.java:31: possible loss of precision     found   : double     required: long          this.acctnum= number;                        ^     flexibleaccount.java:39: cannot find symbol     symbol  : variable number     location: class flexibleaccount          number=generator.nextdouble();          ^     flexibleaccount.java:40: cannot find symbol     symbol  : variable number     location: class flexibleaccount          this.acctnum= number;                    ^ 

how fix , right way overload?

just previous question - there no such variable number when write acctnum = number; in public flexibleaccount(string owner):

public flexibleaccount(string owner)     {      balance = 0;      name=owner;      random generator = new random();      number=generator.nextdouble();        << number not declared      this.acctnum= number;      } 

edit: 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 reason declare 3 arguments although wrote want receive 2 arguments -

public flexibleaccount (double initbal, string owner) – initializes balance , owner specified; randomly generates account number.

i guess wanted have variable number... should more that:

 public flexibleaccount(double initbal, string owner)       {         random generator = new random();          balance = initbal;         name = owner;          this.acctnum= generator.nextlong();         } 

now said in prev. question homework, won't add that. read answers , comments got until , work up.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -