Before you start writing any code for this assignment, please turn in a project plan with estimated lines of code, hours, and defects. After you've finished, compare the actual lines of code, hours, and defects (from your time and defect logs) with your initial estimate. The estimate will probably be far from reality, but that's how you learn to make more accurate estimates next time. I recommend using the PSP forms.
As always, be sure to follow the design recipe. Be sure to choose meaningful names for methods and parameters, and watch for opportunities to re-use methods you, I, or the textbook have already written.
Starting with the StringList class I provided in
class (the one that's implemented using ArrayList, not the
earlier one with subclasses ESL and NESL),
write the following methods:
substitute, which takes in a StringList and two
Strings (oldString and newString) and replaces every
occurrence of oldString in the list with newString.
It returns nothing, but modifies the StringList it was given.
Done in class Apr. 6same, which takes in another StringList
and tells whether the two StringLists contain exactly
the same Strings in the same order.
dictionarySort, which takes in a
StringList and re-orders its elements into dictionary order.
It returns nothing, but modifies the StringList it was given.
TreeSet class: put all the Strings into a TreeSet,
and then when you retrieve them from the TreeSet, they'll be in order.
Of course, this relies on a lot of TreeSet magic going on behind the
scenes. For extra credit, write both this version and
a version in which you do all the comparing and re-ordering yourself,
as you did in Homework 7.
Develop a StringSet class analogous to the
StringList class above, but not allowing duplicates, and
not caring about order. Where I used an ArrayList in
StringList, you should instead use either a
TreeSet or a HashSet. The class should have
the following methods:
StringSetadd method that takes in a String and adds it,
returning true if it was added and false if
it wasn't (i.e. if it was already there)size method that returns the number of Strings in
the StringSetcontains method that takes in a String and tells
whether or not it is in the StringSetremove method that takes in a String and removes
it from the StringSet, returning true if
it was there and false if it wasn't.subset method that takes in another
StringSet and tells whether or not this is a
subset of the other one (i.e. all the elements of
this are also elements of the other StringSet)same method that takes in another
StringSet and tells whether or not it has exactly the
same elements as this.restrict method which takes in another
StringSet and removes all the elements of this
that aren't in the other StringSet; in other words, it
modifies this to be the intersection of what
it was and the other StringSet.This problem deals with voting in an election. You'll need to
re-use the Candidate class from homework 7.
CandidateList class with a constructor,
addAtFront method, addAtEnd method,
contains method, size method,
toString method, etc. Use the built-in
ArrayList class.
results which takes in a
StringList of votes and returns a CandidateList,
sorted by how many votes they got, with the most votes first and the
fewest votes last, just as in homework 7, but using the classes you
just developed.
This problem deals with sets of collections.
Develop a StringListSet class to represent a set of
StringLists. Write a constructor and the methods add,
contains, size, toString,
same, etc. Use the built-in HashSet or
TreeSet class.
Hint: If you use a HashSet of
StringLists, the system may not recognize when two
StringLists are "the same", so it may allow duplicates.
You could just ignore the problem, and accept that sometimes your
StringListSet will contain duplicates... but to really fix
the problem, see here.
Develop a StringSetSet class to represent a set of
StringSets. Write a constructor and the methods add,
contains, size, toString,
same, etc. Use the built-in HashSet or
TreeSet class.
Hint: This will face the same hashing problem: again, see here for ways to fix it.
subsets method that takes in a
StringSet and produces a set of all of its subsets.
scramble method that takes in a StringList and
produces a set of all possible orderings of those strings.
Pretty much the same as the past few assignments.