Skip to content

Instantly share code, notes, and snippets.

@SethJMoore
Last active January 17, 2019 17:20
Show Gist options
  • Select an option

  • Save SethJMoore/e2a09062efab19bab209 to your computer and use it in GitHub Desktop.

Select an option

Save SethJMoore/e2a09062efab19bab209 to your computer and use it in GitHub Desktop.
I made up the wakeUp method to paint on a coffee mug. I put the rest of this together to make sure the method would work. Run it at https://repl.it/@SethJMoore/GeneralGrimNewsaggregator
public class CoffeeMug {
public CoffeeMug() {
isEmpty = false;
}
private boolean isEmpty;
public boolean isEmpty() {
return this.isEmpty;
}
// Print this on a coffee mug.
public void wakeUp(Person p) {
while (p.isSleepy()) {
p.drink(this);
if (isEmpty())
refill();
}
}
public void refill() {
isEmpty = false;
System.out.println("refilling");
}
public void consume() {
isEmpty = true;
}
}
public class Main {
public static void main(String[] args) {
CoffeeMug mug = new CoffeeMug();
Person person = new Person();
mug.wakeUp(person);
}
}
public class Person {
private int sleepyness;
public Person() {
sleepyness = 5;
}
public boolean isSleepy() {
if (sleepyness > 0) {
System.out.println("sleepy");
return true;
}
else {
System.out.println("Awake!");
return false;
}
}
public void drink(CoffeeMug mug) {
mug.consume();
sleepyness--;
System.out.println("drinking");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment