Question
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
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