From fa4e96b1d3d4e18afa9316b09c2b6b55319ff375 Mon Sep 17 00:00:00 2001 From: skyofdream <1662992055@qq.com> Date: Tue, 21 May 2024 17:41:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exp12/Person.java | 21 ++++++++++++++++ exp12/TicketingSystem/TicketingSystem.java | 29 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 exp12/Person.java create mode 100644 exp12/TicketingSystem/TicketingSystem.java 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()