I am new to programing. i know how to return a date

public Date yesterday()
    {
        
        if(this.day == 1)
        {
          if(this.Check("Mar", this.month))
          {
              if (this.checkLeapYear(this.year))
              {
                  this.day = 29;
                  this.weekDay = this.week[this.flipBack(this.week, this.weekDay)];
                  this.month = this.monthOfYear[this.flipBack(this.monthOfYear, this.month)];

              }
              else
              {
                 this.day = 28;
                 this.weekDay = this.week[this.flipBack(this.week, this.weekDay)];
                 this.month = this.monthOfYear[this.flipBack(this.monthOfYear, this.month)];

              }
            }
          if (this.month30Days(this.month))
          {
              this.day = 31;
              this.weekDay = this.week[this.flipBack(this.week, this.weekDay)];
              this.month = this.monthOfYear[this.flipBack(this.monthOfYear, this.month)];
               
          }
          if (!this.month30Days(this.month) || !this.Check("Feb", this.month))
          {
              this.day = 30;
              this.weekDay = this.week[this.flipBack(this.week, this.weekDay)];
              this.month = this.monthOfYear[this.flipBack(this.monthOfYear, this.month)];

          }
        }
        
          this.day = --this.day;
          this.weekDay = this.week[this.flipBack(this.week, this.weekDay)];
        
    }

Recommended Answers

All 8 Replies

what exactly is happening there? i did notice that i didn't see a return in your code there.

also (this won't change the way the program functions), instead of saying "day = --day", you can say "day--".

also (this won't change the way the program functions), instead of saying "day = --day", you can say "day--".

Yes, that will change the way the program works. prefix is evaluated before the variable is used and postfix is evalutaed after. i.e.

int i = 5;
int j = i++;

i = 5;
int k = ++i;

Above j is 5 and k is 6.
So, as you can, it does change the way the program works.

yes, i remembered that bit, but couldn't remember which way around it worked.

but in his program, he says:

day = --day;

where it would be the same as:

day--;

the varialble "day" is given a value of one less than it used to be.

but i still dont have a return statement!!. how do i add it. I need to return yesterdays date??

a simple method:

public int getNumber()
{
    int a = 10;
    int b = 2;
    int c = a * b;

    return c;
}

the return statement is just telling your method what to give when called.

it's like telling your sister she's a method. her job is to tell you how many dolls there are in her room when you call her.

when you say "julie! how many dolls?!" all you're interested in is the number of dolls. you don't want to know how she gets the number. that's a method. you write the method and tell it what kind of information to return (the part just before the method name. in this case, you're telling it to return a Date) then at the end, you tell the method you tell it which variable to return (after you have worked on it).

for this project, what exactly do you need to return? an instance of java.util.Date with yesterday's date, or does the program ask the user to enter today's date like "14 september 2008" and you have to change it to yesterday's date?

Nevermind.

Nevermind.

not quite, good point you made there. also good that you made me remember which one does what. ;)

so mrjoli, how's the project going? also, remember to put your return statement at the end of the method, otherwise the code won't compile.

not quite, good point you made there. also good that you made me remember which one does what. ;)

Na. I said nevermind, because I had originally posted a larger response, then, right after I did it, I realised I had misread a portion of post (the part I had remonstrated about), so, of course, I had to delete it. ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.