Skip to content
This repository has been archived by the owner on May 20, 2020. It is now read-only.

added template #73

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

added template #73

wants to merge 3 commits into from

Conversation

jaydangar
Copy link

Create Template for I/O.

Create Template for I/O.
added Logic part and completed the code.
@Ashwaths
Copy link


title: "Leap Years"
draft: false
date: "2017-10-18T19:07:00"


This short and simple Kata should be performed in pairs using Test Driven Development (TDD).

Prior to 1582, the Julian Calendar was in wide use and defined leap years as every year divisible by 4. However, it was found in the late 16th century that the calendar year had drifted from the solar year by approximately 10 days. The Gregorian Calendar was defined in order to thin out the number of leap years and to more closely align the calendar year with the solar year. It was adopted in Papal countries on October 15, 1582, skipping 10 days from the Julian Calendar date. Protestant countries adopted the Gregorian Calendar after some time.

The Gregorian Calendar is quite accurate, but could be made more accurate by adding an additional rule that eliminates years divisible by 4000 as leap years. But I guess we’ll cross that bridge when we come to it. Consider adding this rule as a second story as an extension to the exercise.

User Story:

As a user,
I want to know if a year is a leap year,
So that I can plan for an extra day on February 29th during those years.

Acceptance Criteria:

  1. All years divisible by 400 ARE leap years (so, for example, 2000 was indeed a leap year),
  2. All years divisible by 100 but not by 400 are NOT leap years (so, for example, 1700, 1800, and 1900 were NOT leap years, NOR will 2100 be a leap year),
  3. All years divisible by 4 but not by 100 ARE leap years (e.g., 2008, 2012, 2016),
  4. All years not divisible by 4 are NOT leap years (e.g. 2017, 2018, 2019).

A leap year is divisible by 4, but is not otherwise divisible by 100 unless it is also divisible by 400

File LeapYear.png shows the trace of my work in this kata. This graph has been generated with Pulse, a plug-in for Eclipse IDE.

@Ashwaths
Copy link

package leapyear;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class TestLeapYear {

private LeapYear leapYear;

@Before
public void setUp() throws Exception {
	leapYear = new LeapYear();
}

@Test
public void when1996_thenIsLeap() {
	boolean isLeap = isLeap(1996);
	assertTrue(isLeap);
}

@Test
public void when2001_thenIsNotLeap() {
	boolean isLeap = this.isLeap(2001);
	assertFalse(isLeap);
}

@Test
public void when1900_thenIsNotLeap() {
	assertFalse(this.isLeap(1900));
}

@Test
public void when2000_thenIsLeap() {
	assertTrue(isLeap(2000));
}


private boolean isLeap(int year) {
	return leapYear.isLeap(year);
}

}

@Ashwaths
Copy link

package leapyear;

public class LeapYear {

public boolean isLeap(int year) {
	boolean result = isMultipleOf4(year) && 
			isNotMiltipleOf100_or_isMiltipleOf100And400(year);
	return result;
}

private boolean isNotMiltipleOf100_or_isMiltipleOf100And400(int year) {
	return (isNotMiltipleOf100(year) || (isMiltipleOf100And400(year)) );
}

private boolean isMiltipleOf100And400(int year) {
	return isMultipleOf(year, 100) && isMultipleOf(year, 400);
}

private boolean isNotMiltipleOf100(int year) {
	return !isMultipleOf(year, 100);
}

private boolean isMultipleOf4(int i) {
	return isMultipleOf(i, 4);
}

private boolean isMultipleOf(int num, int base) {
	return ((num % base) == 0);
}

}

@Ashwaths
Copy link

LeapYear

Copy link
Contributor

@tclavier tclavier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, move your solution un right category.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants