Skip to content

Instantly share code, notes, and snippets.

@GrantSchiller
Last active August 29, 2015 13:56
Show Gist options
  • Save GrantSchiller/9086966 to your computer and use it in GitHub Desktop.
Save GrantSchiller/9086966 to your computer and use it in GitHub Desktop.
public class Cup implements Replenishable {
private int capacity;
private int amount;
public Cup(int c){
capacity = c;
amount = 0;
}
public void fill(int foo) {
if foo + amount > capacity {
amount = 0;
} else {
amount += foo;
}
}
public void empty(int foo) {
if amount - foo >= 0 {
amount -= foo;
}
}
public String checkAmount(){
System.out.println(amount);
}
}
public class Person implements Replenishable {
private int capacity;
private int amount;
public Person(int c){
capacity = c;
amount = 0;
}
public void fill(int foo) {
if foo + amount > capacity {
amount = 0;
System.out.println("*BLARGH* ... I just threw up.");
} else {
amount += foo;
System.out.println("Yum! That tasted good.")
}
}
public void empty(int foo) {
if amount - foo >= 0 {
amount -= foo;
System.out.println("I just pooped.");
}
}
public String checkAmount(){
if (amount > 7){
System.out.println("I feel full.");
} else if (amount > 5) {
System.out.println("I feel pretty darn satiated.");
} else if (amount > 3){
System.out.println("I feel a bit hungry.");
} else {
System.out.println("I am starving.");
}
}
}
interface Replenishable {
void fill(int amount);
void empty(int amount);
String checkAmount();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment