In: Computer Science
Using RAPTOR Create a flowchart and create the pseudocode for the following question
Le Chef Heureux Restaurant has 20 tables that can be reserved at 5 p.m., 7 p.m., or 9 p.m. Design a program that accepts reservations for specific tables at specific times; the user enters the number of customers, the table number, and the time. Do not allow more than four guests per table or invalid table numbers or times. If an attempt is made to reserve a table already taken, reprompt the user. Continue to accept reservations until the user enters a sentinel value or all slots are filled. Then display all empty tables in each time slot.
Here is Solution for Above Program ::
import java.io.*;
import java.util.*;
class Restaurant {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("----------------Welcome to Le Chef Heureux Restaurant-----------------------------------");
int tables=20;
//Here 0 to 19 for time 5.00pm 20 to 39 for time 7.00pm and 40 to 59 for time 9.00pm
int table_check[]=new int[60];
Boolean status[]=new Boolean[60];
for(int i=0;i<60;i++)
{
status[i]=false;
table_check[i]=0;
}
int cust_no=0;
int table_no=0;
int time=0;
System.out.println("\nEnter Details for Reservations Like :: No of Customer(Not more then 4 per table) , Table No(1 to 20) and Time(5,7 and 9 PM) ");
while(true)
{
cust_no=sc.nextInt();
table_no=sc.nextInt();
time=sc.nextInt();
if(cust_no<=4 && table_no<=20 && (time==5 || time==7 || time==9))
{
if((status[table_no-1]==false || table_check[table_no-1]+cust_no<=4)&& time==5 )
{
table_check[table_no-1]+=cust_no;
status[table_no-1]=true;
System.out.println("your request accepted!!");
}
else if((status[20+table_no-1]==false || table_check[20+table_no-1]+cust_no<=4)&& time==7 )
{
table_check[20+table_no-1]+=cust_no;
status[20+table_no-1]=true;
System.out.println("your request accepted!!");
}
else if((status[40+table_no-1]==false || table_check[40+table_no-1]+cust_no<=4)&& time==9)
{
table_check[40+table_no-1]+=cust_no;
status[40+table_no-1]=true;
System.out.println("your request accepted!!");
}
else{
System.out.println("your request Rejected!!");
}
}
else
{
System.out.println("Invalid Entered Details! Please try again!");
}
int c=0;
for(int i=0;i<20;i++)
{
if(status[i]==true && table_check[i]==4)
{
c++;
}
if(status[i+20]==true && table_check[i+20]==4)
{
c++;
}
if(status[i+40]==true && table_check[i+40]==4)
{
c++;
}
}
if(c==60)
{
System.out.println("All Slots are Full!");
break;
}
else{
System.out.println("Waiting for Request!");
int x=sc.nextInt();
System.out.println("Enter 0 for Exit or any key for continue");
if(x==0)
break;
}
}
int sum5=0;
int sum7=0;
int sum9=0;
for(int i=0;i<20;i++)
{
if(status[i]==false)
{
sum5++;
}
if(status[i+20]==false )
{
sum7++;
}
if(status[i+40]==false)
{
sum9++;
}
}
System.out.println("Total Empty Tables for Time 5.00PM "+sum5);
System.out.println("Total Empty Tables for Time 7.00PM "+sum7);
System.out.println("Total Empty Tables for Time 9.00PM "+sum9);
System.out.println();
}
}
Test is Input Look Like ::
input :
4 3 5
1
2 5 9
1
4 4 7
0
Output :
----------------Welcome to Le Chef Heureux Restaurant----------------------------------- Enter Details for Reservations Like :: No of Customer(Not more then 4 per table) , Table No(1 to 20) and Time(5,7 and 9 PM) your request accepted!! Waiting for Request! Enter 0 for Exit or any key for continue your request accepted!! Waiting for Request! Enter 0 for Exit or any key for continue your request accepted!! Waiting for Request! Enter 0 for Exit or any key for continue Total Empty Tables for Time 5.00PM 19 Total Empty Tables for Time 7.00PM 19 Total Empty Tables for Time 9.00PM 19
FLowchart can we developed from above code :
takeinput------>>checking value input ->>>if ok----->>go head --else say invalid details.
from go head to------->> checking table status if all ok ---> accept it else reject it. and ----------->>again takeinput