diff --git a/exp12/Person.java b/exp12/Person.java new file mode 100644 index 0000000..be3633f --- /dev/null +++ b/exp12/Person.java @@ -0,0 +1,21 @@ +package exp12; + +import exp12.TicketingSystem.TicketingSystem; + +public class Person extends Thread{ + + @Override + public void run() { + while (true) { + try { + Thread.sleep(3); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if ( !TicketingSystem.buy(Thread.currentThread().getName())) { + break; + } + } + } +} diff --git a/exp12/TicketingSystem/TicketingSystem.java b/exp12/TicketingSystem/TicketingSystem.java new file mode 100644 index 0000000..010d8d9 --- /dev/null +++ b/exp12/TicketingSystem/TicketingSystem.java @@ -0,0 +1,29 @@ +package exp12.TicketingSystem; + +import java.util.HashMap; +import java.util.Map; + +public class TicketingSystem { + private int tickets = 200; + private Map 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()