From 0ec0d074cc31549f233547d9eb17c432191634f3 Mon Sep 17 00:00:00 2001 From: Jay Ashokbhai Dangar Date: Thu, 14 May 2020 12:49:26 +0530 Subject: [PATCH 1/2] added template Create Template for I/O. --- content/kata/LeapYears.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/content/kata/LeapYears.md b/content/kata/LeapYears.md index 200897e..224d88f 100644 --- a/content/kata/LeapYears.md +++ b/content/kata/LeapYears.md @@ -24,3 +24,29 @@ Acceptance Criteria: 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). +########################################################################################################################## + + Code Starts Here + +########################################################################################################################## +import java.io.*; +import java.util.*; + +Class LeapYearChecker{ + + public static void main(String[] args) throws Exception{ + BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(args[0]))); + Stream inputs = reader.lines(); + Iterator inputLines = inputs.iterator(); + + while(inputLines.hasNext()){ + + } + + reader.close(); + } + + static boolean isLeapYear(){ + + } +} From f163d24f85a35d7d042544f2971c270e760a9dab Mon Sep 17 00:00:00 2001 From: Jay Ashokbhai Dangar Date: Thu, 14 May 2020 13:08:32 +0530 Subject: [PATCH 2/2] Code Completed added Logic part and completed the code. --- content/kata/LeapYears.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/content/kata/LeapYears.md b/content/kata/LeapYears.md index 224d88f..22dedf1 100644 --- a/content/kata/LeapYears.md +++ b/content/kata/LeapYears.md @@ -40,13 +40,35 @@ Class LeapYearChecker{ Iterator inputLines = inputs.iterator(); while(inputLines.hasNext()){ + StringTokenizer tokens = new StringTokenizer(inputLines.next()); + int year = Integer.parseInt(tokens.nextToken()); + if(year<0){ + reader.close(); + throw new Exception("Year cannot be negative"); + } + String printStatementForLeapYear = " is not a Leap Year."; + if(isLeapYear(year)){ + printStatementForLeapYear = " is a Leap Year."; + } + System.out.println("Year " + year + printStatementForLeapYear); } reader.close(); } - static boolean isLeapYear(){ - + static boolean isLeapYear(int year){ + if(year % 400 == 0){ + return true; + } + else if(year % 100 == 0){ + return false; + } + else if(year % 4 ==0 ){ + return true; + } + else { + return false; + } } }