A set is a collection of things, referred to as elements or members of the set. For this assignment, you are to complete the SetOfPerson class. As its name suggests, an instance of this class represents a set of persons. Meanwhile, each person is represented by an instance of the class Person.
To keep things simple, a Person object has only two fields, one for storing a name and the other for storing any other data that we might want to associate with the person that it represents. For our purposes, we care about only the name. In fact, the SetOfPerson class assumes that a person's name uniquely identifies them, which is to say that, even if there were two different Person objects having the same name, they would be treated as though they represented the same person. The only method of interest to us in the Person class is nameOf().
The SetOfPerson class, as provided, includes several "stubbed" methods that need to be completed. It has three instance variables:
Note the specification of the utility findPerson() method, whose sole purpose is to place the resident cursor at the node (within the resident list) holding the member with the specified name (if such a member exists). This makes findPerson() useful to any method that, in order to carry out its purpose, needs to "find" a person with a specified name.
All the Java source code files that you need can be extracted from this zip file. Below are links to individual files.
Welcome to the SetOfPerson Tester Program.
Q (quit)
A (test addPerson())
R (test removePerson())
T (test others)
> A
Start with this set:
Size: 8; Members: { Harry, Melissa, Jack, Xena, Olivia, Zeke, Paul, Farrah }
Enter name of person to add (empty string to quit): Emily
addPerson() returned true; set is now:
Size: 9; Members: { Harry, Melissa, Jack, Xena, Olivia, Zeke, Paul, Farrah, Emily }
Work reported: 8
Enter name of person to add (empty string to quit): Jack
addPerson() returned false; set is now:
Size: 9; Members: { Harry, Melissa, Jack, Xena, Olivia, Zeke, Paul, Farrah, Emily }
Work reported: 2
Enter name of person to add (empty string to quit):
Q (quit)
A (test addPerson())
R (test removePerson())
T (test others)
> R
Start with this set:
{ Wendy, Hannah, Nancy, Sabrina, Jack, Carl, Lisa, Ann }
Enter name of person to remove (empty string to quit): Carl
removePerson() returned true; set is now:
Size: 7; Members: { Wendy, Hannah, Nancy, Sabrina, Jack, Lisa, Ann }
Work reported: 5
Enter name of person to remove (empty string to quit): Ann
removePerson() returned true; set is now:
Size: 6; Members: { Wendy, Hannah, Nancy, Sabrina, Jack, Lisa }
Work reported: 6
Enter name of person to remove (empty string to quit): Hannah
removePerson() returned true; set is now:
Size: 5; Members: { Wendy, Nancy, Sabrina, Jack, Lisa }
Work reported: 1
Enter name of person to remove (empty string to quit): Bill
removePerson() returned false; set is now:
Size: 5; Members: { Wendy, Nancy, Sabrina, Jack, Lisa }
Work reported: 5
Enter name of person to remove (empty string to quit):
Q (quit)
A (test addPerson())
R (test removePerson())
T (test others)
> T
Make a set by entering indices of people[]: 5 36 50 12 9 3
Set A is
Size: 6; Members: { Carol, Sabrina, Zeke, Gail, Ernie, Bill }
Make a set by entering indices of people[]: 50 9 17 24 38 3 20 10
Set B is
Size: 8; Members: { Zeke, Ernie, Ingrid, Mark, Tara, Bill, Karen, Farrah }
unionWith() says A union B is
Size: 11; Members: { Carol, Sabrina, Zeke, Gail, Ernie, Bill, Ingrid, Mark, Tara, Karen, Farrah }
intersectionWith() says A intersect B is
Size: 3; Members: { Zeke, Ernie, Bill }
difference() says A minus B is
Size: 3; Members: { Carol, Sabrina, Gail }
Q (quit)
A (test addPerson())
R (test removePerson())
T (test others)
> Q
Goodbye.
|