Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Assignment #6
- Goals:
- This lab gives students more experience in
- • Top-down design
- • Procedural abstraction using methods.
- Background Information
- 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.
- Requirement:
- 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:
- • If the year is a leap year or not.
- • If the given year is a leap year, your program should then display
- 1. which day of the week was Feb 29th, and
- 2. the next leap year where Feb. 29th happens on the same week day.
- Please note that for this assignment you should create the following two methods:
- 1. The is_leap_year method, which decides if the given year is a leap year or not.
- 2. The zellers method, which accepts the year, month and day and returns the weekday
- (0 – 6).
- 3. The display_day method which accepts the week day (0 – 6) and displays the weekday (Sunday – Saturday).
- NOTE:
- 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.
- Zeller’s Algorithm
- 1. Define Terms
- 0.1 Let DAY an integer number representing the day of the month
- 0.2 Let MONTH an integer number representing the month
- 0.3 Let YEAR be an integer number representing the year
- 0.4 Let DayNumber be the an integer number representing the day of the week( 0 represents Sunday, 6 represents Saturday)
- 0.5 Let StartMonth, StartYear, and LeapFactor be three integer variables used in the calculation
- 2. INITIALIZE Variables
- 1.1 Set DAY , MONTH and YEAR to the date you want to find the week day
- 3. IF MONTH < 3
- 2.1 StartMonth = 0
- 2.2 StartYear = YEAR – 1
- otherwise
- 2.1 StartMonth = INT (0.4 * MONTH + 2.3)
- 2.2 StartYear = YEAR
- 4. LeapFactor = (StartYear / 4) – (StartYear / 100) + (StartYear / 400)
- 5. RETURN DayNumber = ((365 * YEAR + 31 * (MONTH – 1) + DAY + LeapFactor – StartMonth) – 1) MOD 7
Add Comment
Please, Sign In to add comment