Results 1 to 4 of 4
  1. #1
    rampage12345 is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Default Holiday Dates HELP PLEASE!

    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):




    Java Code:
      /* 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;
        }
        }

  2. #2
    javinator is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default Re: Holiday Dates HELP PLEASE!

    This is going to sound weird, but I am 99.99% sure I am in your class (or one on the same day). Please PM me.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Holiday Dates HELP PLEASE!

    Quote Originally Posted by javinator View Post
    This is going to sound weird, but I am 99.99% sure I am in your class (or one on the same day). Please PM me.
    You're the instructor, are you?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    javinator is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default Re: Holiday Dates HELP PLEASE!

    haha, no I'm not. I just PM'd the OP. It's easy to do a Google search on the code comments to see if anyone asked for help online. It saved me the last time. Somehow Google managed to point me to this site not even 30 minutes after this thread was started.

Similar Threads

  1. Dates sometimes off by a day?
    By saggio in forum Advanced Java
    Replies: 13
    Last Post: 12-08-2010, 05:56 PM
  2. Hw Holiday Prac..Happy Turkey Day.
    By Bgreen7887 in forum New To Java
    Replies: 16
    Last Post: 11-25-2010, 05:02 PM
  3. UTC Dates
    By PedroCosta in forum Advanced Java
    Replies: 3
    Last Post: 04-01-2010, 07:08 PM
  4. Difference of Two Dates
    By jboy in forum New To Java
    Replies: 3
    Last Post: 09-15-2009, 07:41 PM
  5. Help with dates
    By bumblyb33 in forum New To Java
    Replies: 1
    Last Post: 02-13-2009, 03:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •