Hello all, I would really appreciate some help. I have an assignment for my class that is due where the objective is for the program to recognize the holiday when a specific date comes around. The easy ones are holidays that fall on a specific date every year, examples such as Christmas and the 4th of July. The part I am stuck with are the holidays that are different every year, such as something like "The fourth Thursday of the month" aka Thanksgiving, in November. If anyone can help with that part I would greatly appreciate it, and here is the program he gave us as it is (incomplete):
/* Application program that produces a list of "known holidays" for a given calendar interval.
The beginning date value and ending date value are either given as command line argument
values or the user as prompted to enter them. In either case, the dates must be given
in the form mm/dd/yyyy. Furthermore, the first date value MUST NOT represent a date later
than the second date value.
*/
import java.util.Scanner;
public class Holidays {
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
// Initialize the starting and ending date values
////////////////////////////////////////////////////////////
SimpleDate start = new SimpleDate(getString(args,0).trim());
SimpleDate stop = new SimpleDate(getString(args,1).trim());
////////////////////////////////////////////////////////////
// Loop to iterate over the interval
while(!start.equals(stop)) {
// Process the current date
String result = holidaysOf(start);
if(result.length() > 0) { //Check for non-empty string result
System.out.println(dayOfWeekAbbreviation(start.getDayOfWeek()) +
" " + start + " " + result);
}
start.nextDay(); //Advance to the next date
}
}
/* Functional Method that returns a string expressing the name (or names) of
the holidays occuring on the given date. If not holiday occurs on the
given date then the empty string as returned indicating this.
*/
static String holidaysOf(SimpleDate date) {
return asChristmas(date);
}
/* Functional Method that returns "Christmas" if the given date
corresponds to the Christmas Holiday, or the empty string if
it does not.
*/
static String asChristmas(SimpleDate date) {
String result = "";
if((date.getMonth() == 12) && (date.getDay() == 25)) {
result = "Christmas";
}
return result;
}
//Constants useful with the getDayOfWeek method
static final int SUN = 1;
static final int MON = 2;
static final int TUE = 3;
static final int WED = 4;
static final int THU = 5;
static final int FRI = 6;
static final int SAT = 7;
/* Functional Method that returns the abbreviation for the given "day of the week
value"; where, 1 == "Sun", 2 == "Mon", etc.
*/
static String dayOfWeekAbbreviation(int dow) {
String result = "???";
if(dow == 1) {
result = "Sun";
}
else if(dow == 2) {
result = "Mon";
}
else if(dow == 3) {
result = "Tue";
}
else if(dow == 4) {
result = "Wed";
}
else if(dow == 5) {
result = "Thu";
}
else if(dow == 6) {
result = "Fri";
}
else if(dow == 7) {
result = "Sat";
}
return result;
}
/* Functional Method that as passed the command line arguments and the
index of the argument desired. If that argument exists then it as
returned as the value of this function; if not then the user as
prompted to enter a string value, which as then returned as the result
of this function.
*/
static String getString(String[] commandLineArgs, int i) {
String result;
if (commandLineArgs.length > i) {
result = commandLineArgs[i];
}
else {
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter "+i+":");
result = keyboard.nextLine();
}
return result;
}
}