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

wirte a program using JAVA l You are the manager of a small Italian bistro. Each

ID: 3598226 • Letter: W

Question

wirte a program using JAVA l

You are the manager of a small Italian bistro. Each hour, your restaurant can accept up to 8 reservations in each time slot. Although it’s a small number of tables, it’s important to keep track of reservations, because business has been very good.

In order to make a reservation, you need to take their name and phone number. Assign (hard code) the names and phone number for the first 5 people using parallel arrays. When the patrons arrive, the hostess will use your program to see if the reservation exists. So, your program should prompt the hostess for a name. If the name is on the reservation list, then you should display the accompanying phone number. If it is not on the list, the hostess should be prompted for a phone number, and add the new reservation to the list. The hostess should be able to continue to add reservations until the maximum of 8 reservations has been reached, so the user should be warned that there are no more available reservations for that hour.  

Explanation / Answer

import java.util.Arrays;
import java.util.Scanner;

public class ReservationBistro {
public static void main(String[] args) {

String name[] = new String[5];// array containing names

String PNumber[] = new String[5];// array containing phone numbers

String res; //

String inputName;// input the patron's name

String inputPhone; // input the patron's phone number if not in list

// add five members to the array

name[0] = "Musthafa";

PNumber[0]="+14456787643";

name[1] = "Hari";

PNumber[1]="+13527757643";

name[2] = "George";

PNumber[2]="+15254678332";

name[3] = "Chrisses";

PNumber[3]="+16679083421";

name[4] = "hotbaby";

PNumber[4]="+12215468907";

Scanner scan = new Scanner(System.in);

// loop continues till there are patrons so as to show the case when the list is full

do {

// check if any patron has arrived or not

System.out.print(" Has any patron arrived(y/n)? ");

res = scan.nextLine();

// if no patron then exit the loop

if(res.equalsIgnoreCase("n"))

break;

// input of the name

System.out.print(" Enter the patron's name: ");

inputName = scan.nextLine();

boolean found=false;

// check if name is present in the list then output the phone number

for(int i=0;i<name.length;i++)

{

if(name[i].equalsIgnoreCase(inputName))

{

found=true;

System.out.println(" Your phone number is "+PNumber[i]);

}

}

// if patron not present in list add to the list if list not full

if(!found)

{

if(name.length != 8) {

System.out.print(" Enter the patron's phone number: ");

inputPhone=scan.nextLine();

name=Arrays.copyOf(name, name.length+1); // copy the array back to itself by increasing its length so as to add the new patron

PNumber = Arrays.copyOf(PNumber, PNumber.length+1);

name[name.length-1] = inputName;

PNumber[PNumber.length-1] = inputPhone;

}else {

System.out.println(" Sorry no tables available for reservation for this hour");

}

}

}while(true);

scan.close();

  

}

}

// End of program