LeapYear Solution

$30.00

Description

File Name:

H:\CPSC1150\Lab6\LeapYear.java

Purpose

To calculate whether the given year is a leap year. If it is, then what day February 29th is on.

.

Input

The year

Output

If it is a leap year or not. If it is then what day February 29th is on

Program Logic (Pseudocode)

Algorithm LeapYear

Start

(main method)

1. Initialize variables

(a) day = 29 in int

(b) month = 2 in int

(c) year in int (user input)

2. Allow the user to enter a year

(a) check to make sure the year is after 1582

(b) if is after 1582 take it to the (is_leap_year method)

(c) return whether the year is a leap year or not

3. if the year is a leap year

(a)Take it to the (zellers mtehod) and give it the day, month, and year

(b) take daynumber and enter it in (week_day method)

(c) Inform user what day February 29th lies on

4. Create a loop to find the next year with February 29th occurring on the same day

(a) The loop parameters should be the year1 starting 4 years after the given year and increases by 4

(b) Put year1 into the (zellers method) and return as daynumber1

(c) check if the daynumber=daynumber1 and check if year1 is a leap year (is_leap_year method)

(d) if it is the same display to the user and exit loop

(is_leap_year method)

  1. Check if it is a leap year and return a Boolean of true if it is and false if it isn’t

  1. If year%4 equals 0

  2. If the year%100 does not equal 0

  3. And if the year%400 equals 0

(zellers method)

  1. Define Terms

    1. Let DAY an integer number representing the day of the month

    2. Let MONTH an integer number representing the month

    3. Let YEAR be an integer number representing the year

    4. Let DayNumber be the an integer number representing the day of the week( 0 represents Sunday, 6 represents Saturday)

    5. Let StartMonth, StartYear, and LeapFactor be three integer variables used in the calculation

  1. INITIALIZE Variables

    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.

(a)LeapFactor = (StartYear / 4) – (StartYear / 100) + (StartYear / 400)

(b)DayNumber = ((365 * YEAR + 31 * (MONTH – 1) + DAY + LeapFactor – StartMonth) – 1) MOD 7

(c) return daynumber

(week_day method)

1.Create a switch statement

(a) set each number to a day with the numbers between 0 and 6

(b) return the given day in string