0

So, here is the issue. I made a Time class which allows me to create time objects. In my time class, I created a method called minutesUntil. minutesUntil tells me the difference in minutes between two times.

To call minutesUntil, I used this line.

time1.minutesUntil(time2)

This is the code in minutesUntil.

 public int minutesUntil(Time other){
    int otherTotalMinutes = other.getMinutes() + (other.getHours() * 60);
    int thisTotalMinutes = ??.getMinutes() + (??.getHours() * 60);
    return (otherTotalMinutes - thisTotalMinutes);
}

What do I use in place of the question marks on the third line to refer to the time1 object inside of the minutesUntil method.

Mantosh Kumar
  • 5,659
  • 3
  • 24
  • 48
Underdisc
  • 163
  • 1
  • 10

2 Answers2

3

If I understand you correctly, you want this; that is

int thisTotalMinutes = ??.getMinutes() + (??.getHours() * 60);

should be

int thisTotalMinutes = this.getMinutes() + (this.getHours() * 60);

Which might also be expressed like

// Using "this" implicitly.
int thisTotalMinutes = getMinutes() + (getHours() * 60);
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • Thanks. I thought I was supposed to use 'this.' , but I didn't get the correct value when I ran the program using 'this.', so I assumed my use of 'this.' was incorrect. After trying again, it worked. I assume I made some stupid mistake. Thank You. :) – Underdisc Apr 29 '14 at 01:28
  • @Underdisc You might need to check which one has a greater value before performing the subtraction. – Elliott Frisch Apr 29 '14 at 01:29
  • That was the first thing I checked and it is working exactly as intended now. Thanks again. :) – Underdisc Apr 29 '14 at 01:31
2

You don't need anything there. Get rid of the dots. Change this:

int thisTotalMinutes = ??.getMinutes() + (??.getHours() * 60);

to this:

int thisTotalMinutes = getMinutes() + (getHours() * 60);

Or use this if you desire, but I see no need to clutter the code with this in this situation.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373