Question
Must be in JAVA. Halifax is finally opening a cat cafe (Catpuccino) and theyre anticipating a lot of visitors on the first day. To avoid
Must be in JAVA.
Halifax is finally opening a cat cafe (Catpuccino) and theyre anticipating a lot of visitors on the first day. To avoid overwhelming the cats, theres a limit to how many people the owners want to allow in at once. Once the cafe is at capacity (no more room), the store wont let anyone in until someone leaves.
Write a program that will track the number of people that enter the cafe and dont let people in if there is no room. Use a Scanner to read in a sequence of integers. The first integer indicates the total capacity of the cafe. Then you will read in a sequence of 1 and 0 (1 means someone wants to enter the cafe and 0 means someone leaves). If someone wants to enter the cafe but it is full, then ignore the request and read the next integer. When -1 is entered, that means that the cafe is closed. When the cafe closes, print out how many people entered the cafe in total.
Details
Input
An integer representing the maximum capacity, followed by a sequence of 1s and 0s, until a -1 is read.
Output
The total number of customers.
Sample input: 10 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 0 1 -1 Sample output: Total Customers: 13
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started