Hi guys revising for an exam and im fine with the theory stuff but heres one question:

A large ornamental garden is open to the members of the public who can enter through two gates: east gate or the west gate. The management wants to determine how many people there are in the garden at any time. Write a program to implement the population count that contains two concurrent threads (each controlling a single gate). The gardens is open 1 hour a day. You can assume during this time no one was allowed to leave. 18marks

This is a closed book exam! So for this I would write two threads east and west. Start them in the main method. Incrementing a counter instance variable, within the run methods of the thread class.

Please correct anything you guys think above. How would you guys prevent the threads interfereing with each other? and how does the 1 hour get into it?

Thanks guys

Recommended Answers

All 3 Replies

synchronise on the counter

Yeah i guess i was thinking it would be something more complex than that but you're right. What about the 1 hour stipulation?

doesn't matter. Just introduce a switch somewhere that opens or closes a gate :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.