15-100
Sections U-V-AA / Spring 2009 / Quiz 3
20 Minutes
Note: On this quiz, you may only
use/call methods that you write yourself (so no Math methods, String methods,
etc), except for print(), println(), charAt(), and length() (which you may
use).
Also note: on this quiz, you may use loops or
conditionals.
- oneEdit
Write
a method named “oneEdit” that takes two strings and returns true if the
first string can be transformed into the second string with exactly one
single edit, and false otherwise (or if either string is null), where an
edit is any one of these three operations:
* Insert a single character (eg, “cat” à “chat”)
* Delete a single character (eg,
“smile” à “mile”)
* Swap a single character (eg,
“cubs” à “cabs”)
Note that the new character in a swap must differ from the character being
swapped out, so in particular a string cannot be transformed into itself
in one edit.
Write three well-chosen helper methods, one for each type of edit (insert,
delete, swap), and write a suitable test method (a single test method for
all cases). Along with “oneEdit”,
that makes five methods, each worth 20% of the quiz grade.
- Bonus/Optional: eToTheX
Based
on the Maclaurin series expansion of ex, we know that:
Using this fact, and not using any Math methods or Math constants, write a
method named eToTheX that takes a double value x and returns ex
to some reasonable degree of accuracy.
Write well-chosen helper methods, both for simplicity and for
partial credit.