Guest User

Untitled

a guest
Feb 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. Assignment #6
  2.  
  3. Goals:
  4.  This lab gives students more experience in
  5. • Top-down design
  6. • Procedural abstraction using methods.
  7. Background Information
  8.  
  9. A year with 366 days is called a leap year. A year is a leap year if it is divisible by 4 (For example, 1996), except that it is not a leap year if it is divisible by 100 (For example, 1900); however, it is a leap year if it is divisible by 400 (for example, 2000); and there were no leap years before the introduction of the Gregorian Calendar on October 15, 1582.
  10.  
  11. Requirement:
  12.  
  13. Design an algorithm, and then write the java program to ask the user to enter a year greater than 1582. Your program then displays the following:
  14. • If the year is a leap year or not.
  15. • If the given year is a leap year, your program should then display
  16. 1. which day of the week was Feb 29th, and
  17. 2. the next leap year where Feb. 29th happens on the same week day.
  18.  
  19. Please note that for this assignment you should create the following two methods:
  20. 1. The is_leap_year method, which decides if the given year is a leap year or not.
  21. 2. The zellers method, which accepts the year, month and day and returns the weekday
  22. (0 – 6).
  23. 3. The display_day method which accepts the week day (0 – 6) and displays the weekday (Sunday – Saturday).
  24.  
  25. NOTE:
  26.  
  27. Use the following algorithm, known as Zeller’s Congruence, to compute a single digit, 0 to 6, for Sunday through Saturday. For example, 22/10/1999 has occurred on Friday since the algorithm returns 5 representing Friday.
  28.  
  29. Zeller’s Algorithm
  30.  
  31. 1. Define Terms
  32. 0.1 Let DAY an integer number representing the day of the month
  33. 0.2 Let MONTH an integer number representing the month
  34. 0.3 Let YEAR be an integer number representing the year
  35. 0.4 Let DayNumber be the an integer number representing the day of the week( 0 represents Sunday, 6 represents Saturday)
  36. 0.5 Let StartMonth, StartYear, and LeapFactor be three integer variables used in the calculation
  37.  
  38. 2. INITIALIZE Variables
  39. 1.1 Set DAY , MONTH and YEAR to the date you want to find the week day
  40.  
  41. 3. IF MONTH < 3
  42. 2.1 StartMonth = 0
  43. 2.2 StartYear = YEAR – 1
  44.  
  45. otherwise
  46. 2.1 StartMonth = INT (0.4 * MONTH + 2.3)
  47. 2.2 StartYear = YEAR
  48.  
  49. 4. LeapFactor = (StartYear / 4) – (StartYear / 100) + (StartYear / 400)
  50.  
  51. 5. RETURN DayNumber = ((365 * YEAR + 31 * (MONTH – 1) + DAY + LeapFactor – StartMonth) – 1) MOD 7
Add Comment
Please, Sign In to add comment