[ mehnihma @ 17.09.2011. 23:00 ] @
Imam zadatak koji trebam napraviti i napravljen je veci dio jos samo to treba staviti u kucice tj napraviti tablicu i sloziti imena unutra: Account Name Owner Balance ovo dobijem na ispisu: Owner = Fred Balance = 75 Owner = Jane Balance = 40 Owner = Fred Balance = 135 Owner = George Balance = 50 A ne znam kako to tocno izvesti, znam napraviti pravokutnik ali nisam siguran ako dalje ovo je kod Code: class Account_1 { String owner; int balance; public Account_1() { } // end constructor Account() public void initialise(String name) { owner = name; balance = 0; } // end method initialise public void deposit (int anAmount) { balance = balance + anAmount; } // end method deposit public int withdraw (int anAmount) { int amountWithdrawn; if (anAmount <= balance) amountWithdrawn = anAmount; else amountWithdrawn = 0; balance = balance - amountWithdrawn; return amountWithdrawn; } // end method withdraw public void print() { System.out.println("Owner = "+ owner +" Balance = "+balance); } // end method print } // end class Account class Account_2 { String owner; int balance; public Account_2() { } // end constructor Account() public void initialise(String name) { owner = name; balance = 0; } // end method initialise public void deposit (int anAmount) { balance = balance + anAmount; } // end method deposit public int withdraw (int anAmount) { int amountWithdrawn; if (anAmount <= balance) amountWithdrawn = anAmount; else amountWithdrawn = 0; balance = balance - amountWithdrawn; return amountWithdrawn; } // end method withdraw public void print() { System.out.println("Owner = "+ owner +" Balance = "+balance); } // end method print } // end class Account class Account_3 { String owner; int balance; public Account_3() { } // end constructor Account() public void initialise(String name) { owner = name; balance = 0; } // end method initialise public void deposit (int anAmount) { balance = balance + anAmount; } // end method deposit public int withdraw (int anAmount) { int amountWithdrawn; if (anAmount <= balance) amountWithdrawn = anAmount; else amountWithdrawn = 0; balance = balance - amountWithdrawn; return amountWithdrawn; } // end method withdraw public void print() { System.out.println("Owner = "+ owner +" Balance = "+balance); } // end method print } // end class Account public class Account { public static void main(String[] args){ Account_1 acc1 = new Account_1(); Account_2 acc2 = new Account_2(); Account_3 acc3 = new Account_3(); acc1.initialise(null); acc1.owner="Jane"; acc1.deposit(100); acc1.withdraw(40); acc2.initialise("Fred"); acc2.deposit(200); acc2.withdraw(125); acc2.print(); acc3.initialise("George"); acc3.deposit(50); acc3.withdraw(75); acc2.deposit(60); acc1.withdraw(20); acc1.print(); acc2.print(); acc3.print(); } } |