diff --git a/LeapYear.java b/LeapYear.java new file mode 100644 index 0000000..dac9c29 --- /dev/null +++ b/LeapYear.java @@ -0,0 +1,56 @@ +/** Class that determines whether or not a year is a leap year. + * @author YOUR NAME HERE + */ +public class LeapYear { + + /** Calls isLeapYear to print correct statement. + * @param year to be analyzed + */ + private static void checkLeapYear(int year) { + if (isLeapYear(year)) { + System.out.printf("%d is a leap year.\n", year); + } else { + System.out.printf("%d is not a leap year.\n", year); + } + } + + /** + * Method check if year is leap + */ + public static boolean isLeapYear(int year) { + if (year % 400 == 0) { + return true; + } else if (year % 100 != 0 && year % 4 == 0) { + return true; + } else { + return false; + } + + } + + public static void countDaysInYear(int year) { + if (isLeapYear(year)) { + System.out.println("366 days"); + } else { + System.out.println("365 days"); + } + } + + + /** Must be provided an integer as a command line argument ARGS. */ + public static void main(String[] args) { + if (args.length < 1) { + System.out.println("Please enter command line arguments."); + System.out.println("e.g. java Year 2000"); + } + for (int i = 0; i < args.length; i++) { + try { + int year = Integer.parseInt(args[i]); + checkLeapYear(year); + countDaysInYear(year); + } catch (NumberFormatException e) { + System.out.printf("%s is not a valid number.\n", args[i]); + } + } + } +} \ No newline at end of file