Due by 12:19 pm on Friday, February 6
- boolean and int data types
- Problem simplification and growth (see class notes for February 4th).
The Programming Problem
Write a program, ValidDate, which is invoked with three integer arguments, representing the year, month, and day (in that order) of a calendar date. The program should print true if the specified date is a valid one in the Gregorian calendar (that is, the standard calendar in use throughout all Western countries). Otherwise, it should print false.
Some essential aspects of valid calendar dates:
No year before 1582 (the year the Gregorian calendar was introduced to the world) is valid.
A month value is between 1 (representing January) and 12 (December).
Day values are always at least 1, and no more than the maximum day possible for the specified month. That means a maximum value of 28 for February (except in leap years, when it's 29), 30 for April, June, September, and November, and 31 for the others.
The program should recognize correct dates even in leap years: you have a leap year if it's divisible by 4, except for when it's also divisible by 100. In the latter case, it's only a leap year if it's also divisible by 400.
John-Lasseter:~ jlasseter$ java ValidDate 2015 2 5 true John-Lasseter:~ jlasseter$ java ValidDate 2012 2 29 true John-Lasseter:~ jlasseter$ java ValidDate 2015 2 29 false John-Lasseter:~ jlasseter$ java ValidDate 1492 6 14 false John-Lasseter:~ jlasseter$ java ValidDate 2015 3 47 false John-Lasseter:~ jlasseter$ java ValidDate 1900 2 29 false John-Lasseter:~ jlasseter$ java ValidDate 2000 2 29 true John-Lasseter:~ jlasseter$ java ValidDate 2015 6 31 false
The goal of this lab is to give you some experience with the material we discussed in class on the separation and delay of concerns during program construction.
Build your ValidDate solution by constructing a series of Java programs that solve increasingly larger parts of the overall problem. There is no single way to do this, so don't worry if your series of problem simplifications/solution expansions is different from mine or others in the class.
The most important part of this lab is that you document your development process. You will do this by describing each stage in your program development, that is, a description of the portion of the problem you're going to solve and the source code for your program that solves this problem.
You will save this documentation in a single file, for which you may use any word processor (MS Office, LibreOffice, etc.). To construct your document, follow these steps:
First, identify an initial outline of the programs's major stages (if you're looking for guidance here, use the material in the February 4 class notes). For example, your program might only solve the problem of printing an answer true for all inputs. It might do nothing other than read its three arguments. It might simply do nothing when it runs. Really, this choice is up to you. Write down what this simplification is; in other words, state clearly what portion of the overall problem your program solves.
Make a complete Java program that correctly solves this version of the problem. This must be a legal Java program! I cannot overstate how important this is. If you cannot compile and run your source code, then you don't have a solution.
Copy and paste this source code into your development document.
Have you finished? Does your program now solve the problem completely? Does it produce the expected results for the example inputs you've chosen? If so, congratulations. Tidy up your lab report, and submit the source code for the final version of your program.
Otherwise decide on an improvement to your solution, that is, a slightly more complete solution to the problem. Go back to step 2, and repeat!
Summary of Expectations
Your program should correctly identify dates that are valid from those that are not. However, substantial partial credit will be given for programs that only solve most of the problem (for example, every date except for February 29 during leap years).
Your lab document should include a minimum of four development stages, each one stating the sub-problem that you're currently solving, and each one including the complete source code for the program that solves it.
This source code included with each documented stage must be a legal Java program, free of all compiler errors, and it must actually solve the stated problem. (That's pretty easy: just copy and paste your code into the document as soon as you get it running.)
I cannot emphasize this enough. Any solution that cannot be successfully compiled with javac will receive no credit. If you run into any trouble here, please ask me for help, which I am always happy to give (as are the TAs). I know this seems draconian, but I promise you'll thank me for it later.
Turn in (READ ME):
Turn in a paper copy of your lab write-up. Since that will include every version of your program, you do not need to give a separate paper copy of your final source code.
Submit an electronic copy of the final version of your program (no need to submit the earlier ones, as I can reconstruct them from your lab writeup). Remember to copy this to your turn in folder:
/classes/cs124/<your last name>/
NOTE: Make sure you're actually copying it to this folder and not your own home folder at /afs/afs.hws.edu/home/<your user name>! This is an obvious source of confusion, and will lead you to think you've turned in your work to me when you haven't.
Also, please respect my file name requests. I ask for precise names because it makes it easier for me to test your work. Thanks.
John H. E. Lasseter