This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
request on simple question
Posted by jay on March 13, 2001 at 7:55 PM
hello I am java begginer I have 2 simple java codes about ATM and I have to edit or add two things to the codes which are 1.ensuring that the bank can have multiple accounts and 2.extending things so that customers can have multiple accounts the codes are as following this is the first one called Account /** * This class represents an account in a bank. * It supports deposits and withdrawals. * @author John Howard (pair: Kim Beazley) */ public class Account { private double balance; //invariant: balance >= 0 private String name; //invariant: has at least one letter /** * Precondition: true * Postcondition: have created Account for accountName with * zero balance. * @param accountName the name of the owner of the account. */ public Account(String accountName) { name = accountName; balance = 0.0; } /** * Precondition: true * Postcondition: returns current balance. * * @return current balance. */ public double getBalance() { return balance; } /** * Precondition: true * Postcondition: returns name of account. * * @return name of account */ public String getOwner() { return name; } /** * Precondition: increment > 0 * Postcondition: balance increased by increment and new * balance returned. * @param increment amount to add to account. * @return the new balance of the account. */ public double increaseBalance(double increment) { balance = balance + increment; return balance; } /** * Precondition: decrement > 0 and decrement < balance * Postcondition: balance decreased by decrement and * new balance returned. * @param decrement amount to remove from the account. * @return the new balance of the account. */ public double decreaseBalance(double decrement) { balance = balance - decrement; if (balance < 0 ) { System.out.println("negative balance error"); System.exit(1); } return balance; } } This is the second one called AccountTester
/** * Runs tests on an Account class * @author Kim Beazley (Pairs: John Howard) */ public class AccountTester { /** * Precondition: true * Postcondition: very basic tests of Account are complete. */ public static void main(String[] args) { Account account = new Account("test"); System.out.println("balance is : " + account.getBalance()); System.out.println("account name is : " + account.getOwner()); account.increaseBalance(10); System.out.println("new balance after adding $10 : " + account.getBalance()); } }
now if you know how to do the questions I said on the top please tell leave the answer here or email me
thank you
Replies:
|