4 Replies - 2394 Views - Last Post: 01 November 2012 - 08:02 PM Rate Topic: -----

#1 avogradoheisenburg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-November 12

Completing method bodies in the SpeedDating class

Posted 01 November 2012 - 04:37 PM

I just need help writing the method bodies. The assignment said I need to create a loop to get credit. The loops must be within the method body. Please help. I've spent so many hours on this and I have no idea where to start. If you can help on writing one of the methods that would be amazing! I think if you can help on one of the methods I can figure out the other two.

/**
 * A class to give students experience using loops.  This class
 * creates and manipulates objects of Greg's Date class.
 */
public class SpeedDating
{
   // Note: this class has no instance variables!

   /**
    * Creates an empty SpeedDating object so that you can call the methods
    * (a constructor that takes no parameters is known as a "default"
    * constructor)
    */
   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
   }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Completing method bodies in the SpeedDating class

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Completing method bodies in the SpeedDating class

Posted 01 November 2012 - 05:10 PM

Based on the comments in the code... you simply posted the code given by your teacher and now you ask us to do your homework :v:
- We are not a code writing service
- We don't do homework

But, we will be glad to help you if you have problem with your code
Welcome at DIC by the way
Was This Post Helpful? 0
  • +
  • -

#3 avogradoheisenburg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-November 12

Re: Completing method bodies in the SpeedDating class

Posted 01 November 2012 - 06:22 PM

I'm sorry. I'm still struggling writing a method. Can you give me some guidance though. Like what I have to do? I'll try to write a code and if I'm able to do so and is incorrect I'll post it here.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Completing method bodies in the SpeedDating class

Posted 01 November 2012 - 06:24 PM

Your teacher seems hot on dates :)
Was This Post Helpful? 0
  • +
  • -

#5 avogradoheisenburg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-November 12

Re: Completing method bodies in the SpeedDating class

Posted 01 November 2012 - 08:02 PM

Does this make sense to you?

while (startYear <= (10 + startYear))
{
startYear = startYear++ ;
}

The instruction were: 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.

So this makes sense right? Let's say user inputs 2012.
2012 is <= 2022 so 2012 become 2013
2013 is <= 2022 so 2013 becomes 2014 and so on.
Or would this mean an infinite loop?

If this is correct how would I go about printing this out on the test class? Instructions: 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

Please don't misinterpret this. I'm not asking you to give me the exact code just give me some guidance. I already created the Date object but I'm getting an error message saying d1 might not have been initialized. What's up?

Date d1 = new Date(d1.getMonth(), d1.getDay(), d1.getYear()) ;

usually when I call a method I use the GET thing. For example, class.getMETHODNAME() but there were no instance variables or anything so I don't know how to extract the information :(
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1