Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. /**
  2. * ---------------------------------------------------------------------------
  3. * File name: DateValidator.java
  4. * Project name: Project 2
  5. * ---------------------------------------------------------------------------
  6. * Creator's name and email: Drew Parsons zldp3@goldmail.etsu.edu
  7. * Course-Section: CSCI1260-201
  8. * Creation Date: Feb 14, 2011
  9. * ---------------------------------------------------------------------------
  10. */
  11.  
  12. /**
  13. * Responsibilities:<br>
  14. * Enter type responsibilities here<br>
  15. *
  16. * <hr>
  17. * Date created: Feb 14, 2011<br>
  18. * <hr>
  19. * @author Drew Parsons
  20. */
  21.  
  22. public class DateValidator
  23. {
  24. private static int daysInMonth = 0; //holds the amount of days in the month
  25. private final static int CURRENT_YEAR = 2011; //this year
  26. private final static int BOTTOM_YEAR = 1800; //holds an old year for data checking
  27.  
  28. public boolean calcDate(int month, int day, int year)
  29. {
  30.  
  31. switch (month)
  32. {
  33. case 1:
  34. case 3:
  35. case 5:
  36. case 7:
  37. case 8:
  38. case 10:
  39. case 12:
  40. daysInMonth = 31;
  41. break;
  42. case 4:
  43. case 6:
  44. case 9:
  45. case 11:
  46. daysInMonth = 30;
  47. break;
  48. case 2:
  49. if ( ((year % 4 == 0) && !(year % 100 == 0))
  50. || (year % 400 == 0) )
  51. daysInMonth = 29;
  52. else
  53. daysInMonth = 28;
  54. break;
  55. default:
  56. return false;
  57.  
  58. }
  59.  
  60. if(day > 0 && day <= daysInMonth && year <= CURRENT_YEAR && year > BOTTOM_YEAR)
  61. {
  62. return true;
  63. }
  64. else
  65. {
  66. return false;
  67. }
  68. }
  69.  
  70.  
  71. /* public String toString()
  72. {
  73. return days1 + "/" + month1 + "/" + year1;
  74. }**/
  75.  
  76. }//end DateValidator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement