Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Having trouble writing the methods for this program

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Having trouble writing the methods for this program

    public SpeedDating()
    {
    } // Constructor has empty body

    /**
    * Prints the day of the week (e.g. "Thursday") on which Halloween will
    * fall for 10 consecutive years.
    * @param startYear the first of the 10 consecutive years
    */
    public void printHalloweens(int startYear)
    {


    // TO DO: write body of this method here
    }

    /**
    * Computes and returns the Date on which Thanksgiving will fall
    * in a given year.
    *
    * NOTE: By law, Thanksgiving is the 4th Thursday in November
    *
    * @param year the year for which to compute the date of Thanksgiving
    * @return the Date of Thanksgiving for the specified year
    */
    public Date getThanksgiving(int year)
    {

    // TO DO: write body of this method here
    }

    /**
    * Computes and returns the number of days between two dates,
    * counting the end date but not the start date. E.g., the
    * number of days between 11/1/2012 and 11/5/2012 is 4, not 5.
    *
    * Precondition: The start date must occur on or before the end date.
    *
    * @param start the earlier of the two dates
    * @param end the later of the two dates
    *
    * @return the number of days elapsed between the start date and the
    * end date
    */
    public int countingTheDays(Date start, Date end)
    {
    // TO DO: write body of this method here
    }
    }


    This is the documentation
    Constructor Summary
    SpeedDating()
    Creates an empty SpeedDating object so that you can call the methods (a constructor that takes no parameters is known as a "default" constructor)

    Method Summary
    int countingTheDays(Date start, Date end)
    Computes and returns the number of days between two dates, counting the end date but not the start date.
    Date getThanksgiving(int year)
    Computes and returns the Date on which Thanksgiving will fall in a given year.
    void printHalloweens(int startYear)
    Prints the day of the week (e.g.

    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait


    Constructor Detail
    SpeedDating

    public SpeedDating()
    Creates an empty SpeedDating object so that you can call the methods (a constructor that takes no parameters is known as a "default" constructor)
    Method Detail
    printHalloweens

    public void printHalloweens(int startYear)
    Prints the day of the week (e.g. "Thursday") on which Halloween will fall for 10 consecutive years.
    Parameters:
    startYear - the first of the 10 consecutive years
    getThanksgiving

    public Date getThanksgiving(int year)
    Computes and returns the Date on which Thanksgiving will fall in a given year. NOTE: By law, Thanksgiving is the 4th Thursday in November
    Parameters:
    year - the year for which to compute the date of Thanksgiving
    Returns:
    the Date of Thanksgiving for the specified year
    countingTheDays

    public int countingTheDays(Date start,
    Date end)
    Computes and returns the number of days between two dates, counting the end date but not the start date. E.g., the number of days between 11/1/2012 and 11/5/2012 is 4, not 5. Precondition: The start date must occur on or before the end date.
    Parameters:
    start - the earlier of the two dates
    end - the later of the two dates
    Returns:
    the number of days elapsed between the start date and the end date

    1. Create a SpeedDating object

    2. Have the user enter a year, and call the printHalloweens method to print the day of the week on which Halloween will occur for the next 10 years, starting with the input year

    3. Have the user enter another year, call the getThanksgiving method, and print the Date object returned. Print the Date in the main method, not in SpeedDating.

    4. Have the user enter another year, call getThanksgiving again, and print the Date object returned again.

    5. Have the user enter the data for two Date objects - an earlier date and a later one. Create the two Date objects, call the countingTheDays method, and print the value returned.
    Assume that the earlier date always occurs before the later one

    I'm not asking for you to do my homework or anything just an explanation on what I have to do. The assignment specified that I just have to complete the method bodies and create a test class. To get credit for the methods I must use a loop. I don't understand why I would need a loop for the getThanksgiving one. I'm so confused. Someone please help me.


  2. #2
    Forum Admin
    Join Date
    Oct 2012
    Posts
    92
    My Mood
    Amused
    Thanks
    9
    Thanked 18 Times in 13 Posts

    Default Re: Having trouble writing the methods for this program

    For syntax highlighting please type [ highlight=Java] before your code segment, and [/highlight] after your code segment. It will make your code more readable here and increase your chances of getting a solution.

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Having trouble writing the methods for this program

    I just reposted this in a nicer way. Should I delete this post?

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Having trouble writing the methods for this program

    You should have edited your original post above, not create a new post.

  5. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Having trouble writing the methods for this program

    How can I delete?

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Having trouble writing the methods for this program

    Just continue on your other post.

Similar Threads

  1. Having trouble writing insert method for Ordered LinkList.
    By orbin in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 28th, 2012, 05:25 PM
  2. Trouble with writing/reading array to/from file
    By MaximusPrime in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 4th, 2012, 08:41 PM
  3. Need Help with Writing methods that involves Loops
    By jslam in forum Loops & Control Statements
    Replies: 7
    Last Post: February 27th, 2012, 01:29 AM
  4. [SOLVED] Writing a program with arrays and class methods... PLEASE HELP?
    By syang in forum What's Wrong With My Code?
    Replies: 17
    Last Post: August 8th, 2011, 07:02 AM
  5. Trouble writing some code...help?
    By bChEos in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: February 7th, 2010, 08:54 PM