Java Constructor help -
//******************************************************* // account.java // // bank account class methods deposit to, withdraw from, // change name on, , string representation // of account. //******************************************************* import java.util.random; 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; } // name of account public string getname() { return name; } //---------------------------------------------- // returns account number. //---------------------------------------------- public long getacctnumber() { return acctnum; } //---------------- //void , close accounts //---------------- public void close() { balance = 0; name += "close"; numaccounts--; } //---------------- //consolidating accounts //---------------- public static account consolidate(account acct1,account acct2) { account newaccount=null; if((acct1.getname()).equals(acct2.getname())) if(acct1.getacctnumber()!=acct2.getacctnumber()) {newaccount= new account(acct1.getbalance()+acct2.getbalance(),string owner); random generator = new random(); acctnum= generator.nextint(); acct1.close(); acct2.close(); } else system.out.println("not allow,same account number"); else system.out.println("can't use other people account"); return newaccount; } //---------------------------------------------- // returns string containing name, account number, , balance. //---------------------------------------------- public string tostring() { return "name: " + name + "\naccount number: " + acctnum + "\nbalance: " + balance; } } please @ //consolidate section. i'm trying is, consolidate acct1 , acct2 1 new account, restrictions acct1 , acct2 has has same name, acct1 , acct2 account number has different each other, , if met, create new account new balance 2 old account, keep same name , randomly generate new account number. there missing in code? wont compile. these errors got
account.java:95: ')' expected {newaccount= new account(acct1.getbalance()+acct2.getbalance(),string owner); ^ account.java:95: illegal start of expression {newaccount= new account(acct1.getbalance()+acct2.getbalance(),string owner); ^ | | next time please tag question homework if (this time i'll it) , format code it'll readable (use buttons above text box). – mbyd apr 11 '11 @ 20:02 | ||
| | this looks very similar your other question few hours ago (and, matter, your question hour before that). pick 1 edit updates, keep things in 1 place? – pops♦ apr 11 '11 @ 20:03 | ||
| | yea it's same one, sorry, didnt know if should edited old 1 or make new one – tuan nguyen apr 11 '11 @ 20:08 |