CPSC 111 2005/6 Winter Term 2, Assignment 2: Artistes and Magicians


Contents: Details | Part 1 | Part 2 | Deliverables

Details

Out: Wed Feb 22 2006
Due: Fri Mar 10 2006, 5:00pm, both hard copy and electronic handin
Value: 4% of final grade (subject to instructor discretion)

Objectives:

Note: Each assignment (and usually each part of each assignment) will include reflection questions. You should include your answers to the reflection questions in a separate text file from your code named README.txt. Please do not submit your questions in any format other than plain text. (Note that neither Microsoft Word nor PDF is plain text! Whatever editor you use to write your source code should be usable to write a plain text README.txt file.) You should answer the reflection questions for all parts of an assignment in the same README.txt file.


Part 1: ASCII Artiste

Contents:
  • Description
  • ASCII Artiste Interface
  • ASCII Artiste Algorithm
  • ASCII Artiste API
  • Hints
  • Reflection Questions
  • Setting Up Your Project
  • Description

    For Part 1 of the assignment, you will create an ASCII Artiste class, with a driver in its main method. ASCII art is the name for an image made only with keyboard characters. The artiste will print out simple versions of the symbols that appear on a deck of cards: diamonds, hearts, and clubs.

    We'll use the following sample interaction with the artiste to explain its interface and function. In the sample below, the user's input is in green for clarity.

    The ASCII Artiste is now inspired to create!
    --------------------------------------------
    
    What size card do you want? (0 or bigger): 9
    Which card suit? (diamonds, hearts, spades): diamonds
        *
       ***
      *****
     *******
    *********
     *******
      *****
       ***
        *
    Play again? ("no" to quit) yes
    What size card do you want? (0 or bigger): 3
    Which card suit? (diamonds, hearts, spades): diamonds
     * 
    ***
     *
    Play again? ("no" to quit) yes
    What size card do you want? (0 or bigger): 10
    Which card suit? (diamonds, hearts, spades): spades
         * 
        *** 
       ***** 
      ******* 
     ********* 
    *********** 
    ***** ***** 
     ***   *** 
        *** 
        *** 
    Play again? ("no" to quit) y
    What size card do you want? (0 or bigger): 8
    Which card suit? (diamonds, hearts, spades): hearts
     ***   *** 
    ***** ***** 
    *********** 
     ********* 
      ******* 
       ***** 
        *** 
         * 
    Play again? ("no" to quit) sure
    What size card do you want? (0 or bigger): -3
    Humph. Size 10 for you, like it or not 
    Which card suit? (diamonds, hearts, spades):  pinstriped
    Humph. I'll just do diamonds 
        * 
       *** 
      ***** 
     ******* 
    ********* 
    ********* 
     ******* 
      ***** 
       *** 
        * 
    Play again? ("no" to quit) yeah
    What size card do you want? (0 or bigger): 0
    Which card suit? (diamonds, hearts, spades): spades
     
    Play again? ("no" to quit) yup
    What size card do you want? (0 or bigger): 6
    Which card suit? (diamonds, hearts, spades):  spades
       *
      ***
     *****
    *******
    *** ***
       *
    Play again? ("no" to quit) no
    Goodbye! 
    

    Artiste Interface

    Your interface should look as much as possible like the sample provided above. In particular, you must:

    The artiste must must handle incorrect user input gracefully in all three cases above. It should not crash, or behave erratically: it should detect that the user input was illegal, and either ask for it again or use a default value. Notice that in the example the artiste handles erroneous input from the user without crashing! (In the example, the user enters -3 and then pinstriped, neither of which is legal.)

    You are free to add any new shapes that you can figure out how to create algorithmically at an arbitrary size to the menu. For example, "boxes" would be quite easy, while "clubs" would be more tricky. You may also personalize the welcoming, prompting, and departing messages as long as they are clear, informative, and respectful. You should clearly document any extensions in your README.txt file, and always finish the core assignment first and ensure regularly that it still works correctly!

    ASCII Artiste Algorithm

    We will focus in this section on how the artiste generates images. The artiste, like all good programmers, is as lazy as possible and creates the shapes out of reusable pieces. You are required to implement the algorithms above for diamonds, hearts, and spades. However, you are free to add new shape types that are created with entirely new algorithms (like clubs!), or to add alternative approaches to generating the three required shapes.

    ASCII Artiste Design/API

    We have provided an API for the ASCIIArtiste class. You are required to implement both the public and private fields, constructors, and methods of this API. You may also add additional functionality in the form of private or public methods and fields. All code that you add, whether it is required implementation or optional additions, must be clear, easily readable, and documented with JavaDoc. Reusing the javadoc comments provided in the API is OK, but acknowledge your use of that text at the top of each file. Any significant or potentially confusing parts of methods should be documented (such as non-trivial loops and conditionals); code that is reused in different parts of a class should be abstracted into a method; and methods that become overly long or complex should be broken down into simpler methods. Finally, be careful to test that the entire public interface for every class works correctly.

    ASCII Artiste API:

    We have provided you with starter code:

    Hints

    Simplify the problem by breaking it down into smaller pieces, solving and testing the simple pieces before combining them to create more complex behavior. We suggest breaking down the problem down and solving it in this order:

    1. Implement the printBox helper method in the ASCIIArtiste class. You should use nested loops: each pass through the outer loop results in one row of the box being printed. You need two inner loops, one to print out each margin space, and one to print out each star. Make sure you know the difference between System.out.println() and System.out.print(). If you need to start a new line after a loop using many individual print statements, you should use a single println statement outside of the loop. Also, you can more easily debug your margin printing code if you temporarily use a non-whitespace character to make its actions easier to see.

    2. Test the box printing using the testing driver provided in the ASCIIArtiste main method. That driver already asks the user for input on what size object to draw.

    3. Implement the printTriangle method in the ASCIIArtiste class. At first, only worry about the case of printing a triangle made of stars pointing upward, with a given height. (Note that we have provided a function to compute a triangle's width given its height.) For each row in your triangle, you will need to print out some spaces and some stars. The proportion of spaces to stars will change depending on the row.

    4. Test your triangle code thoroughly, with different values for height.

    5. Generalize your printTriangle code to create triangles that point either up or down. If you find that you need identical code in more than one place, don't just copy and paste it. Instead, create private helper methods that you can call from multiple places. Look at the printHeartPeaksBody and printHeartPeaks methods for an example of how to do this.

    6. Test your up and down triangle code thoroughly. Make sure that the height and width of the triangles are the same whether they are pointing up or down.

    7. In the driver main method, print out the banner. For now, don't bother asking which shape the user wants, just hardwire the simplest case of the diamond. Create a loop so that the input request and object drawing happens repeatedly, until the user tells it to stop. In that case, print out a signoff message and exit.

    8. Start implementing the printDiamond method of the ASCIIArtiste by simply calling the printTriangle helper method once.

    9. Improve your printDiamond code to draw a diamond by calling the printTriangle method twice, drawing an upward pointing triangle and then a downward pointing triangle. At first, just assume that the width of your diamond is an even number of stars. Don't forget to test for small cases, like sizes of 2 or 1 or 0.

    10. Generalize your diamond drawing code to handle diamonds that are an odd number of stars wide. Test it.

    11. In the driver method, add an input request so that the user can choose one of two shapes to draw: diamond or heart. Be aware that if you used the Scanner nextInt method to read the object size, it leaves the '\n' (end-of-line) character unread on the input. If you then use the Scanner nextLine hoping to get the name of the shape, you'll instead get the empty end of the line that the integer came on. You could use the Scanner next method to get whatever word comes next, ignoring whitespace. Neither choice is perfect! Think about which you'd prefer, or whether there's a better alternative. Think about how your choice affects your interface.

    12. Start implementing the printHeartShape method in the ASCIIArtiste class by having it print out just the bottom part, made of a triangle pointing downwards, using the printTriangle helper method. The height of this triangle should be smaller than the total height of the heart object. In the stub code that we provide, the proportion is 75% for the triangle part and 25% for the rest (the peaks).

    13. Implement the rest of the printHeartPeaks helper method to create the peaks of the heart, and call it before printing out the bottom triangle.

    14. Test your heart drawing code thoroughly. Make sure that the top part is correctly centered with respect to the bottom part.

    15. Generalize the printHeartShape code so that it can print upside down hearts as well as right-side up hearts.

    16. In the driver, add a third kind of object to the input request: a spade.

    17. Start the printSpade method in the ASCIIArtiste class by having it print out an upside down heart, using the printHeartShape helper method. The height of this heart should be smaller than the total height of the spade object. In the stub code that we provide, the proportion is 75% for the heart part and 25% for the box part. Call the printBox helper method to print out the rectangular box that is the stem of the spade object underneath the top part.

    18. Test your spade drawing code thoroughly. Make sure the stem is correctly centered with respect to the top part. To get a really nice-looking symmetric spade, the width of the stem should be an odd number of stars if the widest part of the upside-down heart is odd.

    19. If, and only if, you have spare time after finishing the core assignment, consider adding optional functionality. For instance, the printClub method that we provide only prints out a box, you could refine that to create a shape that's a closer approximation to the club you see on playing cards. Be sure that any extension you create is clearly documented in your README.txt file, and always finish the core assignment first and ensure regularly that it still works correctly!

    Reflection Questions

    Be sure to answer these reflection questions about Part 1 after you finish the part. There are no right answers to these questions, and we don't expect more than a couple of sentences for each question. However, we will grade on your effort to answer throughtfully.
    1. Often it's hard to generate the correct termination conditions for loops. What strategies did you use to test and debug these expressions?
    2. OPTIONAL: What was especially interesting or frustrating about this part of the assignment? What could we have done to make it better for you?

    Setting Up Your Project

    Eclipse: Download the file ASCIIArtiste.java to your computer. Next, open Eclipse, and make a new Project named ASCIIArtiste. Under the File menu select New->Class, and name it ASCIIArtiste. Copy the text of the file that you downloaded into the resulting window.

    Command line: Download the file ASCIIArtiste.java to whatever directory on your computer you'd like to work from. To compile from the directory where you installed your code, use: javac ASCIIArtiste.java. To run from the directory where you installed your code, use: java ASCIIArtiste.


    Part 2: the Professional Magician

    Contents:
  • Description
  • Professional Magician Interface
  • Professional Magician Algorithm
  • Professional Magician Design/API
  • Supporting API: the SimpleGoogleSearch
  • Testing Your Code (and how we'll grade)
  • Setting Up Your Project
  • Hints
  • Reflection Questions
  • Resources Summary
  • Description

    In this part of the assignment, you will create the "Professional Magician" program. The professional magician supposedly reads the "aether" to answer the user's questions.

    In fact, your program will use some tricky Google searches to determine an anwser to the user's question without using the "aether" (whatever that is!) or even understanding the question.

    We'll use the following sample interaction with the professional magician to explain its interface and function. In the sample below, the user's input is in green for clarity.

    Welcome to the Professional Magician's Crystal Ball!
    ----------------------------------------------------


    I am ready to read the aether in my crystal ball and answer your question.
    I can answer questions of the following types:
    1) What is...
    2) Who is...
    3) What was...
    4) Who was...
    Enter the number corresponding to your question or 0 to quit: 1
    Please complete the question: What is the tallest mountain in the world?




    I have scried your answer: the tallest mountain in the world is mount everest.

    I am ready to read the aether in my crystal ball and answer your question.
    I can answer questions of the following types:
    1) What is...
    2) Who is...
    3) What was...
    4) Who was...
    Enter the number corresponding to your question or 0 to quit: 6

    Please enter one of the question types (1-4) or 0. You entered: 6

    I am ready to read the aether in my crystal ball and answer your question.
    I can answer questions of the following types:
    1) What is...
    2) Who is...
    3) What was...
    4) Who was...
    Enter the number corresponding to your question or 0 to quit: two

    Please enter one of the question types (1-4) or 0. You entered: two

    I am ready to read the aether in my crystal ball and answer your question.
    I can answer questions of the following types:
    1) What is...
    2) Who is...
    3) What was...
    4) Who was...
    Enter the number corresponding to your question or 0 to quit: 3
    Please complete the question: What was the answer to problem #5 on last term's CPSC 111 Final Exam




    I cannot scry the answer to your query about the answer to problem 5 on last terms cpsc 111 final exam.

    I am ready to read the aether in my crystal ball and answer your question.
    I can answer questions of the following types:
    1) What is...
    2) Who is...
    3) What was...
    4) Who was...
    Enter the number corresponding to your question or 0 to quit: 2
    Please complete the question: Who is the new Prime Minister of Canada




    I have scried your answer: the new prime minister of canada is stephen harper.

    I am ready to read the aether in my crystal ball and answer your question.
    I can answer questions of the following types:
    1) What is...
    2) Who is...
    3) What was...
    4) Who was...
    Enter the number corresponding to your question or 0 to quit: 0
    Goodbye!

    Professional Magician Interface

    The professional magician works in three phases. First, it prints a banner message to welcome its user. Next, it repeatedly prompts the user for a question and attempts to answer that question. Finally, when the user indicates that it's time to quit, the magician bids the user goodbye.

    The magician prompts the user for a question in two phases. First, it determines what type of question the user would like to ask. The magician provides a menu of question types, from which the user selects one. Notice that the magician handles erroneous input from the user without crashing! (In the example, the user enters 6 and then two as menu options, neither of which is legal.)

    Once the magician has determined the question type, it asks the user to complete a question of that type. The magician then reads the user's question and attempts to answer it. If it can find the answer, the magician reports the answer (as with the Mount Everest and Stephen Harper answers above). Otherwise, the magician reports the uncooperativeness of the aether (as with the CPSC 111 Final Exam answer). Either way, the magician then prompts the user again for a question type.

    Your interface should look as much as possible like the sample provided above. In particular, you must:

    You are free to add new question types to the menu (such as "Who wrote..." questions, or an extra option that accesses a more flexible interface). You may also personalize the welcoming and departing messages as long as they are clear, informative, and respectful. Finally, you can improve on the answer reporting (which currently strips all punctuation, converts to lowercase, and so forth), but be careful if you choose to do this! Fixing the punctuation and capitalization of the reported answer should not cause your magician to fail to find answers that it would otherwise find. (If you don't understand what that means by the end of this document, do not attempt to improve on this aspect of the program!) You should clearly document any extensions in your README.txt file, and always finish the core assignment first and ensure regularly that it still works correctly!

    Professional Magician Algorithm

    We will focus in this section on the question type, question, and answer portions of the magician.

    The magician answers a question in the following steps:

    1. Determine question type: The magician determines the type of question: "what is", "who is", "what was", or "who was". The important part of the question is its key word: "is" for "what is" and "who is" and "was" for "what was" and "who was".

    2. Obtain question: The magician obtains the remainder of the user's question. For example, for "What is the tallest mountain in the world?", the magician works with the phrase "the tallest mountain in the world".

    3. Search Google: The magician searches on Google (using an instance of SimpleGoogleSearch) for the phrase with the key word tacked onto the end. Continuing the above example, the phrase sent to Google would be "the tallest mountain in the world is".

      The magician uses "phrase search" so that the search will find those exact words. In Google, text that is not surrounded by quotation marks is a word search: Google will find a page that contains each word, regardless of their order or proximity on the page. Text that is surrounded by quotation marks is a phrase search: Google will find a page that has exactly those words in their given order together on the page.

      For our example, the search is for "the tallest mountain in the world is". Note that if you search on Google for "the tallest mountain in the world is" with the quotes, it's a phrase search, and Google will only return pages that include all of those words in the specified order together. If you search for the same phrase without the quotes, it's a word search, and Google will return any page that contains all the words, regardless of their order. (In fact, without the quotes, Google will ignore common words that it calls "stop" words such as "is" and "the".)

      Spend a moment right now figuring out how to create a string in Java that looks like "the tallest mountain in the world is" with the quotes. Hint: just "the tallest mountain in the world is" creates the string without quotes. How do you put quotation marks into a string?

    4. Process snippets: Google will return many snippets of text, which are the words nearby your query text on pages that match. (If you're not sure what these snippets are, go to Google and do a search. In Google's list of results will be bits of text from the pages found; those bits of text are the snippets.) The magician will sift through each snippet as follows:

      Create candidate tiles: For each snippet, the magician will create candidate tiles that are longer and longer word sequences from the string immediately after the query phrase. If our example brought back a first snippet of "the tallest mountain in the world is actually Mauna Kea in Hawaii...", the candidates would be groups of words following the phrase sought: "the tallest mountain in the world". In this case, the first three candidates would be: "actually", "actually mauna", and "actually mauna kea". If the second snippet was "...question anyway, the tallest mountain in the world is Mount Everest in the Himalayas...", its first three candidate tiles would be "mount", "mount everest", and "mount everest in".

      The magician will verify each candidate tile with another Google search as follows:

      Verify candidate tiles: For each candidate tile, the magician will verify the tile by testing it with Google. The magician will create a string combining candidates with the key word and original phrase, and check the number of hits returned by a Google search of that string. Again, the right kind of search to use is a "phrase search" so that all words in exactly that order together are found. For our example, the searches would be: "actually is the tallest mountain in the world", "actually mauna is the tallest mountain in the world", "actually mauna kea is the tallest mountain in the world", "mount is the tallest mountain in the world", "mount everest is the tallest mountain in the world", "mount everest in is the tallest mountain in the world", and so forth, all with the quotes. The reasoning for this is that, if some candidate x appears as "x is the tallest mountain in the world" and as "the tallest mountain in the world is x", it's likely to really be the tallest mountain in the world! (How often do you think "actually is the tallest mountain in the world" will appear compared to "mount everest is the tallest mountain in the world"?)

      Read back over that step. How many loops are involved in sifting through each tile produced from each snippet produced from a user's question?

    5. Print best candidate: Finally, the magician picks the candidate out of all the snippets that had the largest number of hits in its verification search and reports it as the answer. In our example, that would be "mount everest" with more than a hundred hits, many more than any of the other candidates.
    You are required to implement this algorithm, and your Professional Magician should use this algorithm for question types 1–4 mentioned in the interface discussion above. However, you are free to add new question types that use enhancements to this algorithm or entirely new algorithms. For example, you might add an "enhanced-what is" question type that builds candidates both by looking after the words from a "phrase is" search and by looking before the words from a "is phrase" search. You could add a "who wrote" question type that searches for "wrote phrase" and verifies by searching for "phrase was written by candidate" or something similar. Or, you might imagine your own extensions. Be sure that any extension you create is clearly documented in your README.txt file, and always finish the core assignment first and ensure regularly that it still works correctly!

    Professional Magician Design/API

    We have provided an API for the Professional Magician's four classes. You are required to include all public fields, constructors, and methods of this API in your implementation. You may follow the private parts of the specification, or you may design your own private methods and fields. However, your design must be clear and easily readable. In other words: all classes, methods, and fields must be documented with JavaDoc (starting from the text provided in the API is OK, but acknowledge your use of that text at the top of each file); any significant or potentially confusing parts of methods should be documented (such as non-trivial loops and conditionals); code that is reused in different parts of a class should be abstracted into a method; and methods that become overly long or complex should be broken down into simpler methods. Finally, be careful to test that the entire public interface for every class works correctly, even if some method is not actually used by the ProfessionalMagician program.

    The APIs for the four classes in the Professional Magician design are:

    We have also provided you with starter code (in the form of "stubs": minimally functional versions of the files) for each of the four files — see the section entitled Setting Up Your Project below. However, if you would rather get extra practice, you may certainly write these yourself from scratch.

    Supporting API: the SimpleGoogleSearch

    You will use two jar files — googleapi.jar and SimpleGoogleAPI.jar — and a "log" file — test.log — to access Google. All of these files are distributed inside ProfessionalMagician.zip. (For more information on how to use these files, see the section entitled Setting Up Your Project below.) The file googleapi.jar contains Google's Java search API. Because it uses concepts we have not yet discussed, we provide the class SimpleGoogleSearch in the file SimpleGoogleAPI.jar. SimpleGoogleSearch bypasses the concepts that we have not discussed. It also provides a testing interface described below.

    The only class you'll need to use directly from SimpleGoogleSearch.api is SimpleGoogleSearch, described in the SimpleGoogleSearch API.

    We will use SimpleGoogleSearch's testing interface to mark your assignment! Therefore, while you're free to investigate the actual Google API, you are required for this assignment to use instances of SimpleGoogleSearch for all your searches.

    Testing Your Code (and how we'll grade)

    A SimpleGoogleSearch can be constructed in three modes: normal, logging, and logged. You can read about these modes in the documentation for the SimpleGoogleSearch class.

    The most important mode for your grade is logged mode, which is the mode we'll use to mark your assignment. In this mode, a SimpleGoogleSearch does not actually access Google to perform searches. Instead, it accesses a list of previous Google searches stored in test.log. This list of previous searches should contain everything needed to answer the questions below (with the answers given in parentheses). Because the searches are stored on your computer, you can use this mode without a connection to the Internet and without a valid Google API key. We will test your program in logged mode on questions like these (and possibly some extra ones not listed below).

    (Note: if you try a search that is not in the log, you'll see text like Search failed unexpectedly. Error was: com.google.soap.search.GoogleSearchFault: no logged entry exists for the query: "my foot is", and SimpleGoogleSearch's doSearch method will return false. The doSearch method will also return false in logging and normal modes with a different error message if a problem occurs like losing your internet connection or exceeding your allowed number of searches per day on your Google key.)

    In normal mode, a SimpleGoogleSearch will actually access Google to perform searches. Logging mode is like normal mode except that it adds any searches you make to the stored list of searches. Both normal and logging mode require a valid Google search key. The one in the sample code is shared among all CPSC 111 students but limited to 1000 searches per day. So, although it is not required for the assignment, we urge you to create and use your own key by registering for the Google API with your @ugrad.cs.ubc.ca e-mail address (but not your @ugrad.cs.ubc.ca password; pick a new one!) and following the directions e-mailed to that address. If you already have a GMail or Google account, you can also register for a Google API key directly.

    Setting Up Your Project

    This section includes instructions to help you get started with this project in Eclipse and from the command line. You are free to use other development environments for this assignment; however, we do not have instructions for how to get set up in any other environment!

    Setting up in Eclipse: Start by downloading the file ProfessionalMagician.zip to your computer. Next, open Eclipse, and make a new Project named ProfessionalMagician. Under the File menu select Import.... Select Archive file as the import source and browse to the ProfessionalMagician.zip file that you just downloaded. For the Into folder, choose ProfessionalMagician and hit Finish.

    Now, your project contains all the necessary code (including the test.log file and the "stubs" discussed in the Hints below), but the SimpleGoogleAPI.jar and googleapi.jar files are not on your classpath. Right-click on the ProfessionalMagician project and select Properties. In the menu on the left, select Java Build Path. Select the Libraries tab on the right. Click Add Jars.... You should see ProfessionalMagician in the dialog box that pops up. When you double-click on it, you should see the two jar files SimpleGoogleAPI.jar and googleapi.jar. Select one of them, hit OK, and then use Add Jars... again to add the second one. Finally, hit OK to leave the dialog.

    You should now be ready to solve the assignment in Eclipse.

    Setting up on the command line: Start by downloading the file ProfessionalMagician.zip to whatever directory on your computer you'd like to work from. Next, unzip the file to that directory. (The Home Suite Home CD and the lab computers have FilZip for unzipping files; you may have another application.)

    To compile from the directory where you installed your code, use:

    javac -classpath .;googleapi.jar;SimpleGoogleAPI.jar *.java

    To run from the directory where you installed your code, use:

    java -classpath .;googleapi.jar;SimpleGoogleAPI.jar ProfessionalMagician
    Note the dot at the start of the classpath arguments! That's crucial so Java knows to look in the current directory for classes and files. On some computers, you may need to use :s rather than ;s in the commands above.

    Hints

    This is a much larger program than any you've written before in 111. However, you can simplify the problem by breaking it down into smaller pieces, solving and testing those pieces separately, and then putting the pieces together to make a complete program. Therefore, two of the keys to solving this assignment will be to understand how to break the problem into pieces and to understand how the pieces fit together.

    Here are some examples of how to break the problem into pieces:

    Using techniques like this, you can solve this large problem in manageable pieces. Even if you think you can write the whole thing together without much trouble, we recommend trying to write it in pieces like this as practice for larger programming problems you'll face in the future!

    Now, how do you put the pieces together? Well, consider the ProfessionalMagician class. In one sense, it is responsible for doing everything in the whole program. On the other hand, it can use the QuestionAnswerer class to do most of the work of actually answering users' questions! Check out the answer method in QuestionAnswerer and think about how much easier it will be to write ProfessionalMagician using that method.

    Similarly, a QuestionAnswerer must implement the algorithm described in the Professional Magician Algorithm section above. That's a complex algorithm that requires, among other things, searching for strings on Google, cleaning up text inputted by the user or retrieved from Google, and finding the candidate "tiles" from a Google snippet. However, accomplishing each of those tasks in QuestionAnswerer is easy if it relies on the SimpleGoogleSearch, TextCleaner, and StringTiler classes to help. StringTiler, in turn, will rely on TextCleaner to clean input provided to it.

    Read through that description a few times (and draw the relationships on a sheet of paper!). Once you understand how the pieces fit together and how to build the individual pieces, you're a big step toward solving the entire problem!

    Reflection Questions

    Be sure to answer these reflection questions about Part 2 after you finish the part. There are no right answers to these questions, and we don't expect more than a couple of sentences for each question. However, we will grade on your effort to answer throughtfully.
    1. Sometimes it's hard to see where a nested loop actually is because a loop in one class calls a method in another class that contains a loop of its own. Trace through your code carefully starting from the main method of ProfessionalMagician.java. What is your deepest nested loop, and how deep is it? (Hint: it's certainly more than one loop deep if you finished the assignment correctly!) Was it hard or easy to write a loop so deep? What was it about the structure of your program that made it hard or easy?
    2. Did you end up using "stubs" (minimally functional versions of classes or methods) and "drivers" (simple test programs) in your testing? If so, how difficult was it to write and use a stub? A driver? If not, why not, and can you imagine a programming problem where you would use them?
    3. OPTIONAL: What was especially interesting or frustrating about this part of the assignment? What could we have done to make it better for you?

    Resources Summary

    Here is a comprehensive list of the resources you will need for this assignment. All of these are described in more detail in the assignment writeup above.
  • APIs:
  • ProfessionalMagician API
  • QuestionAnswerer API
  • TextCleaner API
  • StringTiler API
  • SimpleGoogleSearch API (the only one that you use but do not need to implement)
  • Files:
  • TextCleanerDriver.java, a sample driver file for testing the TextCleaner class
  • ProfessionalMagician.zip, which includes (among others):
  • test.log
  • googleapi.jar
  • SimpleGoogleAPI.jar
  • Other sites:
  • Google
  • Google's Java search API
  • Registration for a Google API key on a new account (use your @ugrad.cs.ubc.ca e-mail address)
  • Registration for a Google API key from an existing Google account (if you already have a Google or GMail account, but using the previous link may still be preferable!)
  • The java.util.logging.Logger class, which may be helpful for producing debugging output

  • Deliverables



    Last modified: 2006/02/22