Course Links

Exercises

Resources

External

Below is a more detailed description of what your program should do. This is more or less a pseudocode for the assignment, and is given this week only to get you started. You may wish to compare it to a Python program which follows the same pseudocode. For this particular assignment, the Python code and the Java code are (almost) line-by-line translations of each other. This may not be exactly the case for more complex programs, since one language may provide a feature that is not implemented in exactly the same way in the other.

Here is what your program should do: [Hints on creating your Java implementation are shown in red. See the Python-to-Java handout for more details and hints.]

Feel free to depart somewhat from the above, so long as your program accomplishes the same goals. For instance, if a different set of variables seems more useful to you, you may design your program accordingly. Or you could add new methods that perform small tasks that occur more than once, like adding a line to the conversation record. Part of your grade will be based upon the elegance and efficiency of your solution. Extra credit may also be granted in cases where students extend the assignment beyond what is required, although this is at sole discretion of the professor. For example, there are types of input where the mirror word process described above will not work properly. Can you fix the program so it works on these? If you wish, you may submit a solution to the base assignment and a second program with more ambitious goals.

Does the Java syntax still seem awkward? It may, but the extra precision becomes useful in larger programs. In addition to the syntax changes, the program description has changed in a few other minor ways as well. For example, Java does not offer a String.count() method, so the detection of mirror words had to be changed slightly. Also, your program will have to precompute the total number of lines in the conversation in advance rather than appending lines one at a time.

If that last restriction seems awkward, there is another refinement you can attempt. An arbitrary-length conversation is difficult to do with arrays, which require their size to be allocated in advance. The Vector class works somewhat like an array but can be extended in size as needed. The program could be rewritten to use a Vector<String> to store the conversation. This gets into areas of Java we haven't covered yet, which is why it is not part of the main assignment. If you attempt it, please turn in the basic version as well.