java - Why isn't this creating an object? -
could @ portion of code i'm trying void , close account? want achieve:
"2. add method void close() account class. method should close current account appending “closed” account name , setting balance 0. (the account number should remain unchanged.) decrement total number of accounts."
when tried compile it, program gave me error identifier being expected. missing?
//*******************************************************/ // account.java // // bank account class methods deposit to, withdraw from, // change name on, , string representation // of account. //*******************************************************/ public class account { private double balance; private string name; private long acctnum; //---------------------------------------------- //constructor -- initializes balance, owner, , account number //---------------------------------------------- public account(double initbal, string owner, long number) { balance = initbal; name = owner; 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"); } //---------------- //track how many accounts //---------------- private static int numaccounts=0; { numaccounts++; } public static int getnumaccounts() { return numaccounts; } //---------------------------------------------- // adds deposit amount balance. //---------------------------------------------- public void deposit(double amount) { balance += amount; } //---------------------------------------------- // returns balance. //---------------------------------------------- public double getbalance() { return balance; } //---------------------------------------------- // returns account number. //---------------------------------------------- public long getacctnumber() { return acctnum; } //---------------- //void , close accounts //---------------- public void close(account) { balance = 0; name = "close"; acctnum = number; numaccounts--; return account; } //---------------------------------------------- // returns string containing name, account number, , balance. //---------------------------------------------- public string tostring() { return "name: " + name + "\naccount number: " + acctnum + "\nbalance: " + balance; } }
public void close(account) needs variable name. declaration says takes account parameter, need give parameter name e.g. public void close(account account).
note don't think makes sense. given account object should able close it, perhaps should reconsider whether parameter makes sense.
Comments
Post a Comment