Questions and answers for A3, CSC108S

Below questions answered (and answers questioned) for Assignment 3, CSC108S.

Saturday March 15
Why do I need so many files to use StringTriviaTester?

Answer: I originally posted all the .txt files that you'd need in testing. Now I've improved (I hope) things so that StringTriviaTester generates all the files it needs. So, you should now be able to download the one file, compile it in the same directory with your StringTrivia.java file, and then push Test

Friday March 14
In NumberInfo.getClosestFraction it says to return the double whose fractional part is closest to zero. What if there is more than one?

Answer: Since this is not specified in the handout, you get to make a choice. You could pick the first one, or the last one, for example. Neither choice is wrong, since this was not specified.

Thursday March 13
Should isSubsequence("abc", "abc") return true or false?

Answer: true, since "abc" can be formed from "abc" by deleting zero characters. I've revised the method comment to:

/**
 * Return whether s can be formed from t by deleting (but not
 * re-ordering) zero or more of t's characters.  For example,
 * "abc" can be formed from "RaTbbNcQ" by deleting R, T, b, N,
 * and Q.  Notice that if s is the empty String ("") this true
 * for EVERY t!
 * Precondition: s != null && t != null
 */

Thursday March 13
Where do I get the files GuessDivisors.html and BracketGuessDivisors to submit?

Answer: That should be (and now is) BracketGuessDivisors.html and GuessDivisors.html. These are produced when you run javadoc on GuessDivisors.java and BracketGuessDivisors.java.

Thursday March 13
Is there some simple way to test our assignment before we submit it?

Answer: Choosing and applying test cases is a difficult art. However, there are tools that may help. Here is StringTriviaTester, a class that tests StringTrivia. These are exactly the tests I plan to use in marking your work (I won't make all my other test classes public for about a week). To use it, you need to put it in a directory with your StringTrivia.java, plus download zeroText, alphaText, and alphaZeroText. Once you've done that, open StringTriviaTester in drJava, compile, and then click the Test button (upper right).

Once you've tried this out (and assured yourself that you'll ace the StringTrivia part of A3, you may want to try your hand at writing tester class of your own. Notice that all the test methods start with the word "test", are void, and take no parameters. Also junit.framework.* is imported, and the class extends TestCase. To find out more about this tool --- the Junit test framework --- click "help" in DrJava and read on.

Wednesday March 12
Does "oFo" constitute a non-overlapping pair of 'o's?

Answer: No. You're meant to find non-overlapping pairs of adjacent characters (and the handout has now had this added). I've also added the precondition that the String may not be null, so you don't have to worry about checking this.

Monday March 10
Why is the return type for getThreeSumDifference double? Won't this method always find an int to return?

Answer: You're right. The handout is hereby modified to specify int for the return type of getThreeSumDifference. I will have to accept both return types as correct (so I'll build a bonus mark into the marking scheme).

Wednesday March 5
Many of the methods have a precondition in the comment specifying them. What are we supposed to return if the precondition is not met?

Answer: It is the responsibility of the client (user) of your code to meet the precondition. You don't even have to check whether the precondition is met. The way to read this is that you promise to do what is specified in the method comment so long as the user satisfies the precondition. Otherwise (if they don't meet the precondition) all bets are off.

Wednesday March 5
In TabularStuff.printTriangle we're asked to produce (n/2)+1 lines of output. I don't seem to get that many, no matter what I do.

Answer: Ooops, that should read (and now does read) (n/4)+1 lines of output. Hope that helps.


Danny Heap
Last modified: Sat Mar 15 13:57:46 EST 2003