/** This method gets the name of the student to whom the guest should be added * and the guest detail. It then attempts to add the guest to that student. */ private void addGuest() { int result; // Get input details int num = getNumber("Enter student's number: "); String guestName = getDetail("Enter guest's name: "); String guestEmail = getDetail("Enter guest's email address: "); Guest newGuest = new Guest(guestName, guestEmail); // Now try to add the guest to the student result = thisCeremony.addGuest(num, guestName, guestEmail); if (result > 0) { Console.WriteLine("Guest added to student" + num); } else { Console.WriteLine("ERROR: Guest not added to student " + num); if (result == 0) { Console.WriteLine("The guest list for " + num + " is full"); } else { Console.WriteLine("Student " + num + " not found"); } } }
/** * YOU HAVE TO COMPLETE THIS METHOD. * Adds a new guest to a guest list. Duplicate guests are not allowed * @param newGuest * @return true if guest is added * false if the list is full or the guest is already on the list */ public bool addGuest(Guest newGuest) { if (!this.getGuestList().Contains(newGuest)) { try{ this.getGuestList().Add(newGuest); } catch(ArgumentOutOfRangeException){ return false; } return true; } return false; }
/** * YOU HAVE TO COMPLETE THIS METHOD. * Adds a guest to a student. Returns: * -1 if the student's name was not in the list * 0 if guest list is full * 1 if guest successfully added */ public int addGuest(int number, String guestName, String email) { int result = -1; Guest newGuest = new Guest(guestName, email); Student temp = new Student(number, " "); if (myList.Contains(temp)){ Student tmpStudent = (from student in myList where student.Equals(temp) select student).First(); if (tmpStudent.addGuest(newGuest)) { result = 1; } else { result = 0; } } return result; }