11

while (this.isAwake()){
if (this.timeSinceLastCoffee.toString() == "5hr") {
this.cup.refill();
this.drinkCoffee();
}
}

Comments
  • 3
    So if it's 6 hours since coffee or 5 hours 1 minute, do you not get a refill?
  • 0
    @DeveloperACE refill is called instantly when it's equal to 5hr
  • 1
    Why does this class not implement something like

    public interest hoursSinceLastCoffee() {}

    Send like that would make more sense to me, then you could do

    if (this.hoursSinceLastCoffee() >= 5) {}

    I mean, you know, if I were to implement something similar...
  • 0
    What language requires so many references to "this"? I can only think of python, but clearly, this is very far from python
  • 0
    @YousifMansour yeah, I know, but to me it looks like you're code is assuming that the hours since last coffee is always going to increase linearly. What if daylight savings happens right as it hits 5 (or before?) then you actually have 6 hours since last coffee
  • 3
    Eww string comparisons
Add Comment