Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program that controls access to a popular new restaurant. The resta

ID: 642206 • Letter: W

Question

Write a Java program that controls access to a popular new restaurant. The restaurant is not allowed to have more than 100 people in it at any time. Groups of people can always leave, but a group cannot enter if they would make the total number of occupants in the restaurant exceed the maximum. Your program will repeatedly prompt the user for the size of the next group arriving or departing the restaurant. You can use negative numbers to represent departures. After each number is read from the user, display the current number of occupants. As soon as the restaurant reaches the maximum number of occupants, report to the user that the restaurant is full and end the program.
Your program must use a while loop.

Explanation / Answer

import java.io.*;
class rest
{
void rest1() throws Exception
{
int max=100;
int n;
int total=0;
do
{

System.out.println("enter group");
BufferedReader br = new BufferedReader(new InputStreamReader(null));
String r =br.readLine();
n=Integer.parseInt(r);

if(n==max)
{

System.out.println("Sorry entry restricted due to no vacant seat");
}
else
{
total=n+total;
}

System.out.println("group total "+total);

System.out.println("group gone");
total=total-n;
}while(n==100);

}
public static void main(String a[])
{
rest r= new rest();
}}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote