This week, we are going to write a couple of programs from scratch. These programs will require arithmetic and boolean operations, as well as conditional statements and loops.
How do you know if a particular year is a leap-year? The rules are a little more complex than you might think: A leap year is divisible by 4, but not by 100, unless it is divisible by 400. So, 1984 was a leap-year. 1900 was not a leap-year. 2000 was, as you may recall, a leap year, and so will 2400.
Your assignment: Write a program named LeapYear that takes, as an integer, a year number. Your program should determine whether the given year is or is not a leap-year, and should emit output indicating the conclusion to the user.
Your program should have a particular limitation. Specifically, the concept of a leap-year was only instituted about 250 years ago; it only applies to years beyond 1753. Therefore, if the user enters a year prior to 1753, your program should (politely and clearly) inform the user that the requested year pre-dates leap-years. It should then give the user another opportunity to enter a valid year number.
How to get started: Unlike last week, you will be starting your program from scratch. The steps below will get you started.
mkdir lab-2
cd lab-2
xemacs &
class LeapYear { public static void main (String[] args) { } // End of main } // End of class LeapYear
When your work is complete, you should submit it using the cs11-submit command, like so:
cs11-submit lab-2 LeapYear.java
Remember that you can test to be sure that your work was submitted with the cs11-check-submission command. Also remember that if you re-submit your work for a given lab, the previous submission will be clobbered. Be sure, therefore, always to submit a completely working program.