Last active
January 17, 2019 17:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| public static void main(String[] args) { | |
| CoffeeMug mug = new CoffeeMug(); | |
| Person person = new Person(); | |
| mug.wakeUp(person); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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