some code samples, various examples of simple modeling ideas and some minor algorithms.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. class Account
  2. {
  3. private int amount;
  4. public Account()
  5. {
  6. amount = 0;
  7. }
  8. public Account(int sum)
  9. {
  10. amount=sum;
  11. }
  12. public void deposit(int sum)
  13. {
  14. amount+=sum;
  15. }
  16. public boolean transfer(Account acc, int sum) {
  17. if(sum<=amount) {
  18. amount-=sum;
  19. acc.amount+=sum;
  20. return true;
  21. }
  22. else return false;
  23. }
  24. public Account open(int sum) {
  25. if(sum<=amount) {
  26. amount-=sum;
  27. return new Account(sum);
  28. }
  29. else return null;
  30. }
  31. public int balance() {
  32. return amount;
  33. }
  34. public void withdraw(int sum) throws AccountException {
  35. if(sum<=amount)
  36. amount-=sum;
  37. else
  38. throw new AccountException("overdraw");
  39. }
  40. }