| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
-
- class Account
- {
- private int amount;
-
- public Account()
- {
- amount = 0;
- }
-
- public Account(int sum)
- {
- amount=sum;
- }
-
- public void deposit(int sum)
- {
- amount+=sum;
- }
-
- public boolean transfer(Account acc, int sum) {
- if(sum<=amount) {
- amount-=sum;
- acc.amount+=sum;
- return true;
- }
- else return false;
- }
-
- public Account open(int sum) {
- if(sum<=amount) {
- amount-=sum;
- return new Account(sum);
- }
- else return null;
- }
-
- public int balance() {
- return amount;
- }
-
- public void withdraw(int sum) throws AccountException {
- if(sum<=amount)
- amount-=sum;
- else
- throw new AccountException("overdraw");
- }
-
- }
|