Final answer:
To complete Rudie's program, we initialize an array of Guest objects with three guests and write a loop to search for a guest's name in the GuestList. If found, the name is printed; otherwise, a message indicating the name was not found is displayed.
Step-by-step explanation:
To help Rudie complete their Java program for storing and searching a guest list in a restaurant, we need to perform two tasks. First, we will create and initialize an array of Guest objects. Then, we will write code to search the GuestList array for a name entered by the user and display the result.
Initializing GuestList Array
(a) We can declare the array and initialize it with the given guest information:
Guest[] GuestList = new Guest[3];
GuestList[0] = new Guest("Deborah Henry", 8);
GuestList[1] = new Guest("Jennifer Logan", 8);
GuestList[2] = new Guest("Tailor Swift", 7);
Searching the GuestList
(b) To search for a guest, we will iterate over the GuestList array:
for (Guest guest : GuestList) {
if (guest.getName().equalsIgnoreCase(name)) {
System.out.println(guest.getName());
found = true;
break;
}
}
if (!found) {
System.out.println("Name not found");
}