Quantcast
Channel: Why isn't this creating an object? - Stack Overflow
Viewing all articles
Browse latest Browse all 10

Why isn't this creating an object?

$
0
0

Could someone look at the portion of my code where I'm trying to void and close an account? This is what I want to achieve:

"2. Add a method void close() to your Account class. This method should close the current account by appending “CLOSED” to the account name and setting the balance to 0. (The account number should remain unchanged.) Also decrement the total number of accounts."

When I tried to compile it, the program gave me an error about an identifier being expected. What am I missing?

//*******************************************************/// Account.java//// A bank account class with methods to deposit to, withdraw from,// change the name on, and get a String representation// of the account.//*******************************************************/public class Account{  private double balance;  private String name;  private long acctNum;  //----------------------------------------------  //Constructor -- initializes balance, owner, and account number  //----------------------------------------------  public Account(double initBal, String owner, long number)  {    balance = initBal;    name = owner;    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");  }//----------------//Track how many accounts//----------------    private static int numAccounts=0;    {        numAccounts++;        }    public static int getNumAccounts()    {        return numAccounts;        }  //----------------------------------------------  // Adds deposit amount to balance.  //----------------------------------------------  public void deposit(double amount)  {    balance += amount;  }  //----------------------------------------------  // Returns balance.  //----------------------------------------------  public double getBalance()  {    return balance;  }    //----------------------------------------------  // Returns account number.  //----------------------------------------------  public long getAcctNumber()  {    return acctNum;  }//----------------//Void and close the accounts//----------------public void close(Account){    balance = 0;    name = "CLOSE";    acctNum = number;    numAccounts--;     return Account;     }  //----------------------------------------------  // Returns a string containing the name, account number, and balance.  //----------------------------------------------  public String toString()  {    return "Name: "+ name +"\nAccount Number: "+ acctNum +"\nBalance: "+ balance;   }}

Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images