Write the following methods on StringLists:
concatAll
, which returns a String formed by
concatenating all the strings in the list, in order.contains
, which takes in a String and returns a
boolean indicating whether that string exactly matches any of the
ones in the list.
equals
method on Strings.prefixAll
, which takes in a String and returns a
StringList formed by sticking that string in front of each
of the strings in the list. For example, if the variable
people
contained the strings "Jones", "Brown", and
"Smith", then people.prefixAll("Mr. ")
would contain
the strings "Mr. Jones", "Mr. Brown", and "Mr. Smith".append
, which takes in another StringList and
returns a StringList formed from the elements of the recipient list
followed by those of the parameter list. For example, if the
variable people1
contained the strings "Joe" and
"Mary", and people2
contained the strings "Bill",
"Phyllis", and "Jane", then people1.append(people2)
would contain the strings "Joe", "Mary", "Bill", "Phyllis", and
"Jane", in that order.stutter
, which returns a list twice as long as the
one it was given, in which each string is repeated twice in
succession. For example, if the variable people
contained "Joe" and "Mary", then people.stutter()
would
contain "Joe", "Joe", "Mary", and "Mary" in that order.removeFirst
, which takes in a String and returns a
StringList just like the original, but in which the first occurrence
of the specified String is removed. (If the string doesn't appear
in the StringList at all, it should return a StringList just like
the original.)sort
, which returns a list containing the same
strings as the original, but in alphabetical order.
insertInOrder
which takes in a String, assumes that the
StringList it's working on is already in alphabetical order, and
produces a list with the new string inserted in its appropriate
place. This method in turn will need to use the built-in
compareTo
method on Strings.
sort
method took me 12
lines of code, including the headers of both sort
and
insertInOrder
in all three classes, leaving
only 6 lines of real code; it's not all that complicated.Modify your program from Homework 5 to handle an indefinite number (a list) of bouncing objects. Every time the event timer ticks, ALL of the objects (no matter how many) should move (and bounce, if they've hit a wall), and when the user clicks the "set color" button, ALL of the objects should change colors. Add some more buttons to your "controls" window: "add " and "remove"; the "add" button will add a new object (at a random location and velocity) to the list, causing it to move around with the rest, and the "remove" button will remove the most-recently-added object from the list, causing it to disappear.
If you've got two or more different kinds of objects (as assigned in homework 5), create an "add" button for each: for example, if you had the two classes SmileyFace and BoxWithX, you would have an "add : homework 5), create an "add" button for each: for example, if you had the two classes SmileyFace and BoxWithX, you would have an "add smiley face" button and an "add box with x" button. The one "remove" button will still remove the most-recently-added object, regardless of which kind it is.
Write a class named RecursionProblems
containing the following methods. (If you know what a
static
method is, you should probably make these
static
, because they operate on Strings or numbers
rather than user-defined objects. If you don't, don't worry about it.)
copies
, which takes in a natural number
(i.e. 0, 1, 2, 3, ...) and a String, and returns a
StringList with that many copies of the given String.
countSubstrings
, which takes in two Strings and tells
how many times the first appears in the second. For example,
countSubstrings("ab","xyabacabraabz")
should be 3,
and countSubstrings("aa","abaaab")
should be 2.
Hint: You may want to use the built-in
startsWith
method of the String class.
Extra credit: a method named match
,
which takes in two Strings and returns a boolean
telling whether the first matches the pattern in the second.
The catch is that the "pattern" string may contain "?" characters,
which match any single character, and "*" characters, which
match any zero or more characters. For example,
match("abc","abc")
should be true,match("abc","acb")
should be false,match("abc","a?c")
should be true,match("abc","a*")
should be true,match("abc","a*b")
should be false,match("abc","a*b*")
should be true,match("aabc","*a*b*")
should be true, andmatch("aabc","*a?b*")
should be false.equals
on the whole strings); then add the
"?" pattern, and once that works, add the "*" pattern. Don't try to
do this using loops, if you know about them; it's much
harder that way!
Before you start writing the programs, estimate how long they'll be, how long they'll take you to write, and how many defects you'll encounter in them. Enter these estimates in the PSP form. (If this is a major difficulty for you, you can record it in a text file or on paper.)
While working on the program, record your errors and how much time you spend on various aspects of the programming process, again using the PSP form.
You will not be graded on how close your estimate is, or how many errors you make, or how much time you spend, as long as I think all three of them are realistic. You will be graded on whether you record all this stuff. And don't wait until the program is finished to write the estimate; it's time-stamped, and you'll lose credit if it's dated the night before the assignment is due.
You should have two or three BlueJ projects -- one with all the StringList methods, one with the modified version of homework 5, and perhaps another with the RecursionProblems class (or you could just add the Recursion Problems class to the same project as StringList, since one of the methods uses StringLists). Zip each of these folders and attach them to an email to me.
If you've entered your estimates, defects, and time use in PSP, I've already got the data so you have nothing else to turn in. If you prefer recording it some other way, turn that in with your program.