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

Create a WalkIn Class that stores the first and last name of the customer, and a

ID: 653847 • Letter: C

Question

Create a WalkIn Class that stores the first and last name of the customer, and assign a unique sequential number for the walkin.

Then, create a RestaurantQueue (linkedList) which follows the FIFO order, and as a customer comes into the restaurant without a reservation, you will create an instance of the WalkIn class, and add it to the restaurant's queue. Then, after selecting menu option to sit the next person in the queue, start going through the queue, and letting the customers into the restaurant sit at a table. As the customer is called, his object is removed from the restaurant queue.

Details:

1.) Create an addWalkIn(WalkIn aCustWalkIn) method that will add a new WalkIn object to the RestaurantQueue.

2.) Create a fillEmptyTable() method that will sit a customer in the next available table by taking the next customer at the beginning of the Restaurant Queue. The method will print "Here's your table " + firstName + " " + lastName (of the aCustWalkIn object). The method will also remove the object, aCustWalkIn, from the RestaurantQueue, by calling the removeFromQueue() method.

3.) Create a toString() method that will traverse through the RestaurantQueue, and create a String of all the customer walk-ins in the queue. It will print the last and first name, along with the walk-in time.

4.) In the same Driver class you have already created from the Reservations, do the following steps to test the queue:

a.) Create a new WalkIn for Elvis Presley at 5pm.

b.) Create a new WalkIn for Michael Jackson at 5:30pm.

c.) Create a new WalkIn for Frank Sinatra at 5:45pm.

d.) Make a table available for the first customer in the queue (i.e. Elvis).

*** Say to Michael that he will be the next person seated (hint: use the peek method to determine the next person in queue without getting it).

e.) Make a table available for the first customer in the queue (i.e. Michael).

*** Say to Frank that he will be the next person seated.

f.) Make a table available for the first customer in the queue (i.e. Frank).

*** Say there are no more persons waiting to be seated as walk-ins (hint: check if peek returns null).

5.) For testing purposes, print the contents of the WalkIn Queue after each new walk-in. For the version you turn in,

print the queue after all walk-ins are in it, and then after all walk-ins have gotten their tables.

Java

Explanation / Answer

import java.util.*;

class WalkIn

{

    String FName;

    String LName;

    String ETime;

    int seqnumber;

   

    public WalkIn(String FirstName, String LastName, String EntryTime, int seqnum)

    {

       FName=FirstName;

       LName=LastName;

       ETime=EntryTime;

       seqnumber=seqnum;

    }

   

    public String getFName()

    {

       return FName;

    }

   

    public String getLName()

    {

       return LName;

    }

   

    public String getEntryTime()

    {

       return ETime;

    }

   

    public int getSequence()

    {

       return seqnumber;

    }

}

class Reservation

{

   LinkedList<WalkIn> lnkguests = new LinkedList<WalkIn>();

  

  

   public void addWalkIm(WalkIn objwlk)

   {

           lnkguests.add(objwlk);

   }

      

   public void removeFromQueue(WalkIn objwlk)

   {

          lnkguests.remove(objwlk);

   }

  

   public void fillEmptyTable()

   {

         

          WalkIn aCustWalkIn = lnkguests.getFirst();

         

          System.out.println("Here's you table " + aCustWalkIn.FName + " " + aCustWalkIn.LName);

          removeFromQueue(aCustWalkIn);

   }

  

   public String toString()

   {

          for(WalkIn objwlk : lnkguests)

          {

                 System.out.println("First Name :" + objwlk.FName + ", Last Name :" + objwlk.LName + ", Walk In Time :" + objwlk.ETime);

          }

         

          return "";

   }

  

   public void run()

   {

          int iseq=0;

          WalkIn wlk1 = new WalkIn("Elvis", "Presley", "5 pm",iseq++);

          addWalkIm(wlk1);

         

          WalkIn wlk2 = new WalkIn("Michael", "Jackson", "5:30 pm",iseq++);

          addWalkIm(wlk2);   

         

          WalkIn wlk3 = new WalkIn("Frank", "Sinatra", "5:45 pm",iseq++);

          addWalkIm(wlk3);   

         

          toString();

         

          fillEmptyTable();

         

          while(lnkguests.peekFirst() != null)

          {

          System.out.println("Next Person to be seated is :" + lnkguests.peekFirst().FName + " " + lnkguests.peekFirst().LName);

          toString();

          fillEmptyTable();

          }

         

          System.out.println("No more person available for seating!!!");

         

   }

}

public class Restaurant

{

       public static void main(String[] args)

       {

              Reservation rr=new Reservation();

              rr.run();

       }

}