Skip to content

Instantly share code, notes, and snippets.

@tterrag1098
Created July 12, 2015 05:58
Show Gist options
  • Save tterrag1098/e624b89350c563b01e34 to your computer and use it in GitHub Desktop.
Save tterrag1098/e624b89350c563b01e34 to your computer and use it in GitHub Desktop.
public class ATM {
private static final int MAX_AMOUNT = 60; //Euros
private int current = 0;
public synchronized void withdraw(int amount) {
if (amount > MAX_AMOUNT - current) {
return;
}
current += amount;
}
public synchronized void checkIfHacked() {
if (current > MAX_AMOUNT) {
System.out.println("Someone is rich :P!");
} else {
System.out.println("Maximum limit exceeded, try again tomorrow");
}
}
}
public class Main {
public static void main(String[] args) {
ATM atm = new ATM() {
@Override public synchronized void withdraw(int amnt) { current += amount; }
};
atm.withdraw(100);
atm.checkIfHacked();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment