SA-2
Dartmouth is hosting a reunion for former students and their families. You’ve been asked to help track the guest list.
Exercises
-
Attendee.java
: Write a class called Attendee to represent one person who might attend the reunion. Your constructor should take the person’s name and a Boolean if they have RSVP’d to the reunion as parameters. Store these values in instance variables. Provide getters and setters for each. Also add atoString
method so when an object of typeAttendee
is printed, it outputs the person’s name. -
Graduate.java
: Create a subclass ofAttendee
calledGraduate
to represent one Dartmouth graduate who may attend the reunion. Graduates are attendees and in addition to the parameters stored byAttendee
, each graduate should also have a numeric graduation year (e.g., 24) and a department (e.g., Computer Science). Provide the needed parameters in a constructor, saving them in instance variables. If aGraduate
is printed it, should have the same output the same as anAttendee
but should append the year and department. For example:Elvis '23 Computer Science
. -
Reunion.java
: Complete a class calledReunion to track people who may attend. The constructor should accept and store the maximum number of attendees, and should have one array (note: use an array, not an ArrayList!) that can hold up to the max parameter number ofAttendee
orGraduate
objects. Additionally, -
Provide one method (e.g., not two overloaded methods) called
addAttendee
for yourReunion
class that takes an object of either typeAttendee
orGraduate
as a parameter and adds it to the array at the next open spot in your array. This method should print an error message and return if attempting to add more than the maximum number of attendees (including those people rvsp'ed false). If a person is successfully added to the array, print "Added <person>, rsvp: <rsvp>" where <person> is a String representation of the person (examples below, especially Alice and Charlie) and <rsvp> is their rsvp status. -
Provide a method called
rsvp
for yourReunion
class that takes a person’s name as a String and a Boolean indicating if they have RSVP’d as parameters. Search the array ofAttendees
and update the person’s RSVP status if an attendee’s name matches the name parameter (assume no duplicate names). Print “<name> not found” if no attendees names match, where <name> is the name parameter. Otherwise, print the attendee's name and new rsvp status. - Finally, provide a
toString
method that will produce a String representation of a Reunion object in the format shown below. Make sure to be efficient! (e.g., loop through the array one time)
Starting with this scaffold code, your code should produce the following output
Added Alice, rsvp: true
Added Bob, rsvp: false
Added Charlie '22 Government, rsvp: true
Added Denise '21 Econ, rsvp: false
Added Elvis '23 Computer Science, rsvp: true
Unable to accommodate Falcon '26 Biology, max attendees is 5
Reunion attendees that have RSVP:
Alice
Charlie '22 Government
Elvis '23 Computer Science
Reunion attendees that have NOT RSVP:
Bob
Denise '21 Econ
Update rsvp status
George not found
Set RSVP to true for Bob
Reunion attendees that have RSVP:
Alice
Bob
Charlie '22 Government
Elvis '23 Computer Science
Reunion attendees that have NOT RSVP:
Denise '21 Econ
Submission Instructions
Turn in your completed Java code for Attendee
, Graduate
, and Reunion
in one zip file. Make sure your output matches the output above.