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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!