Created
July 12, 2015 05:58
-
-
Save tterrag1098/e624b89350c563b01e34 to your computer and use it in GitHub Desktop.
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 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"); | |
} | |
} | |
} |
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) { | |
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