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();
}}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.