29 lines
612 B
Java
29 lines
612 B
Java
|
package exp12.TicketingSystem;
|
||
|
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
public class TicketingSystem {
|
||
|
private int tickets = 200;
|
||
|
private Map<String, Integer> map = new HashMap<>();
|
||
|
final int MAX_PERSON = 5;
|
||
|
final int MAX_TICKET_PER_PERSON =10;
|
||
|
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
|
||
|
}
|
||
|
|
||
|
public synchronized boolean buy(String user) {
|
||
|
if(!map.containsValue(user) && map.size()<MAX_PERSON) {
|
||
|
map.put(user, 1);
|
||
|
this.tickets--;
|
||
|
}else if(map.get(user) < MAX_PERSON) {
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
}
|