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 Date
class from homework 3 and 4,
monthName
method (or write it if you
didn't before) so that it uses an array or an ArrayList instead of a
huge "if" statement.
(The toString
method should still call monthName
.
If you prefer, you could drop the monthName
method
entirely and just refer to the array or ArrayList from within
toString
.)dayInYear
method (or write it if you
didn't before) so that it uses an array or an ArrayList to keep track
of the number of days in each month.daysLater
method (or write it if you
didn't before so that it handles month lengths and both positive and
negative numbers of days "later".The built-in String
class has a lot of predefined
methods, but not everything you might conceivably want to do with a
String. Chapter 10 of the Gee book shows how to write recursive methods
on Strings, similarly to what we did with lists in Homework 7:
public static whatever doSomething (String s) { if (s.length() == 0) { return // whatever the answer is for the empty string } else { // s.charAt(0) the first character in the String // s.substring(1) the rest of the String // doSomething (s.substring(1)) the answer for the rest of the String return // something involving s.charAt(0) and doSomething(s.substring(1)) } }
Write a Dummy
class with the following methods:
countVowelsRecursively
which takes
in a String and returns the number of vowels ("a", "e", "i",
"o", and "u") in it. It should work recursively, like the
above example.
countVowelsWithWhile
which
does the exact same thing, but it uses a while
loop
instead of recursion.countVowelsWithFor
which
does the exact same thing, but it uses a counter-based
for
loop instead of recursion or a while
loop.The scramble
method of homeworks 7 and 8 was sort
of unnatural: in a real newspaper word-scramble game, you scramble
the letters in one word to get a list of words rather than scrambling
a list of words to get a list of lists of words.
Write a static
method scramble
that takes in a single String and
returns a StringSet or StringList containing all the possible
reorderings of the characters in that String. (You may use any
version of StringSet or StringList
that you've previously written, whether from Homework 7 or Homework
8, or you could even just use a Set<String>
.)
A common task in computer science is pattern-matching:
given a pattern, ask whether a particular string matches it.
In our pattern language, a "?" stands for "any single
character," while "*" stands for "any zero or
more characters." For example, the pattern "c?t"
would match "cat" and "cut" but not
"colt", "cats", or "dog".
Similarly, the pattern "cat*" would match the strings
"cat", "cats", "catastrophe", etc. but
not "caltrop" or "dog". The pattern
"a??a*r" would match "abbatoir", "akbar",
and "araaar", etc. but not
"almoner", "alakazam", or "fnord".
Write a static method matches
that
takes in two Strings -- a pattern and a target -- and returns a
boolean indicating whether the target matches the pattern. Note
that the "special" characters "?" and
"*" are special only when they appear in the
pattern; if they appear in the target, they should be treated as
ordinary characters.
Pretty much the same as the past few assignments.