| Assignment
02: Dates Fall 2007, David Matuszek |
Your program is going to ask the user which of three things to do:
Start with the following outline. Create a project in Eclipse named Dates.
Create a class in that project, also called Dates. Then copy and paste the
following code into the Dates class, replacing the initial code that Eclipse
created for you.
/** * Assignment 2 for CIT591, Fall 2007. * @author Dave Matuszek * @author Replace this with your name! * @author Replace this with your partner's name! * @version Sep 11, 2007 */ public class Dates { /** * Computes day of the week for specific dates, and the number * of days between two dates. * * @param args Not used. */ public static void main(String[] args) { new Dates().run(); } /** * Asks the user whether to find and print the day of the week, * find and print the number of days from one date to the next, * or quit. */ private void run() { boolean quitting = false; while (!quitting) { // Ask the user whether to: find and print the day of the week, // find and print the number of days from one date to the next, // or quit. If quitting, set the boolean variable 'quitting' // to true. } } /** * Asks the user for a specific date, determines what day of * the week it falls on, and prints that day. */ public void findAndPrintDayOfWeek() { // Ask the user for a date (year, month, day) // Call findDayOfWeek to find what day of the week it is // Print the result } /** * Determines what day of the week a given date falls on. * * @param year The year. * @param month The month (January = 1, December = 12). * @param day The day of the month. * @return One of the Strings "Sunday", "Monday", "Tuesday", * "Wednesday", "Thursday", "Friday", or "Saturday". */ public String findDayOfWeek(int year, int month, int day) { return null; // TODO replace this with the name of the weekday } /** * Asks the user for two dates, determines how far apart * (in days) those dates are, and prints the result. */ public void findAndPrintDaysApart() { } /** * Determines how far apart (in days) two given dates are. * If the two dates are the same, the result is zero; if * the second date occurs before the first date, the result * is negative. * * @param year1 The year of the first date. * @param month1 The month of the first date. * @param day1 The day of the month of the first date. * @param year2 The year of the second date. * @param month2 The month of the second date * @param day2 The day of the month of the second date. */ public int findDaysApart(int year1, int month1, int day1, int year2, int month2, int day2) { return 0; // TODO replace this with the correct value } }
Use exactly the class name, method names, and method parameters as given. You can create additional methods, but you must also have the given ones as specified. Any additional methods should also have Javadoc comments.
Here is the month code table:
Jan |
Feb |
Mar |
Apr |
May |
Jun |
Jul |
Aug |
Sep |
Oct |
Nov |
Dec |
|---|---|---|---|---|---|---|---|---|---|---|---|
0 (6 in leap years) |
3 (2 in leap years) |
3 |
6 |
1 |
4 |
6 |
2 |
5 |
0 |
3 |
5 |
Here is the algorithm you should use.
| Algorithm | Example |
|---|---|
|
|
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", and "Saturday". Please get the spelling correct.
Here's the easiest way to do this:
Java has some built-in classes for working with dates. You are not permitted to use them for this assignment; I want you to do the computations yourself.
This assignment has been designed so that you and your partner need to work together on part of it, and can do the other parts separately. However, you should work together as closely as feasible; in particular, you should read and test each other's code before you submit the project.
There is a method for computing leap years on my slides; feel free to use it.
Good advice: Once you have tested your program and made sure it works, submit it without making any additional changes. Errors can creep in at the last minute, even if all you think you are doing is adding or changing comments.
Thursday, September 20, before midnight. Turn in your program electronically, using Blackboard. (See my Instructions for Using Zip Files and Blackboard). Only assignments submitted via Blackboard will be accepted--do not send your program by email. The usual late penalty of 5 points per day (out of 100 points) will apply.