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

Date.java 889B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. class Date
  2. {
  3. protected int day,month,year;
  4. public Date(int d,int m,int y) throws DateException
  5. {
  6. day=d;
  7. month=m;
  8. year=y;
  9. if(month<1||month>12||day<1)
  10. throw new DateException(toString());
  11. else if((month==4||month==6||month==9||month==11)&&day>30)
  12. throw new DateException(toString());
  13. else if(month==2)
  14. {
  15. if(year%4==0)
  16. {
  17. if(day>29)
  18. throw new DateException(toString());
  19. }
  20. else if(day>28)
  21. throw new DateException(toString());
  22. }
  23. else if(day>31)
  24. throw new DateException(toString());
  25. }
  26. public String toString()
  27. {
  28. return day+"/"+month+"/"+year;
  29. }
  30. public boolean lessThan(Date d)
  31. {
  32. if(year<d.year)
  33. return true;
  34. else if(year==d.year)
  35. if(month<d.month)
  36. return true;
  37. else if(month==d.month)
  38. if(day<d.day)
  39. return true;
  40. return false;
  41. }
  42. }