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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. {
  36. if(sum<=amount)
  37. amount-=sum;
  38. else
  39. throw new AccountException("overdraw");
  40. }
  41. }