//*******************************************************
// FlexibleAccount.java
//
// A bank account class with methods to deposit to, withdraw from,
// change the name on, and get a String representation
// of the account.
//*******************************************************
import java.util.Random;
public class FlexibleAccount
{
private double balance;
private String name;
private long acctNum;
//----------------------------------------------
//Constructor -- initializes balance, owner, and 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 to see if balance is sufficient for withdrawal.
// If so, decrements balance by 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 to balance.
//----------------------------------------------
public void deposit(double amount)
{
balance += amount;
}
//----------------------------------------------
// Returns balance.
//----------------------------------------------
public double getBalance()
{
return balance;
}
//----------------------------------------------
// Returns a string containing the name, account number, and balance.
//----------------------------------------------
public String toString()
{
return "Name: " + name +
"
Account Number: " + acctNum +
"
Balance: " + balance;
}
}
This is what i have and I'm trying to overload the FlexibleAccount 3 times as follow
- public FlexibleAccount (double initBal, String owner, long number) – initializes the balance, owner, and account number as specified
- public FlexibleAccount (double initBal, String owner) – initializes the balance and owner as specified; randomly generates the account number.
- public FlexibleAccount (String owner) – initializes the owner as specified; sets the initial balance to 0 and randomly generates the account number.
When I compiled i get 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 do I fix this and is this the right way to overload?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…