Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help in java: You are the manager of Chauncey's Choice. You need to control the number of people who can be in the cafe

Need help in java: You are the manager of Chauncey's Choice. You need to control the number of people who can be in the cafe at the same time. Groups of people can always leave the cafe, but a group cannot enter the cafe if they would make the number of people in the cafe exceed the maximum of 50 occupants. Write a program that reads the sizes of the groups that arrive or depart. Use negative numbers for departures. After each input, display the current number of occupants. As soon as the cafe holds the maximum number of people, report that the cafe is full and exit the program. State that "due to social distancing, no further patrons are allowed".

Having a problem getting my code to not allow more than 50 people in the cafe and having the program terminate once more than 50 people try to enter until more people leave.

My code so far:

publicstaticvoidmain(String[] args) {

//TODOAuto-generated method stub

finalintMAX_PEOPLE = 50;

intnumPeople = 0 & -1 %2;

intavailableGroup = MAX_PEOPLE;

intgroup = numPeople % 2;

Scanner console =newScanner(System.in);

while(availableGroup > 0) {

System.out.print("People entering or leaving: " );

numPeople = console.nextInt();

if(availableGroup >= numPeople) {

group = numPeople + group;

System.out.println("Number of people in cafe: " + group);

}if(group > 50) {

System.out.println("Cafe is full due to social distancing, no further patrons");

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Combinatorial Testing In Cloud Computing

Authors: Wei-Tek Tsai ,Guanqiu Qi

1st Edition

9811044805, 978-9811044809

More Books

Students also viewed these Programming questions

Question

Solve the inequality x 2 x and graph the solution set.

Answered: 1 week ago