Lab: Statement Pretty Print

Objective

In this lab you will practice manipulating Statement values by implementing and testing the Statement prettyPrint secondary method.

Setup

To get started, import the project for this lab, StatementPrettyPrint, from the StatementPrettyPrint.zip file available at this link. If you don't remember how to do this, see the Setup instructions in an earlier lab.

Method

  1. First carefully look through the file Statement1PrettyPrint1.java, which is an extension for Statement1 that overrides the StatementSecondary implementation of the prettyPrint method, and make sure that you familiarize yourself with the methods provided. Note that it includes a main method used to test the implementation of prettyPrint.
  2. In Statement1PrettyPrint1.java, complete the body of the prettyPrint instance method by pasting the code you wrote for the homework. Here are a few things to keep in mind:
    • The contract for prettyPrint is informal and vague. To see what the output of prettyPrint is supposed to look like, open the SampleStatement.bl file in the data folder. Your implementation of prettyPrint must generate this output if called on the Statement object corresponding to the SampleStatement BL statement (with indentation 0 from the left edge of the page).
    • prettyPrint must restore the value of this.
    • Your solution has to be recursive.
  3. When you have completed the implementation of prettyPrint, run the Statement1PrettyPrint1 test program. You can use the SampleStatement.bl file in the data folder in your project as a test input. The main program generates two output files (both in the data folder): expected-output.txt that contains the correct output for the given program and actual-output.txt that is the output generated by your implementation. Eclipse provides a convenient way of comparing files. In the Package Explorer view, open the data folder and select both output files (click on the first one and then CTRL-click on the second one to select them at the same time). Then right-click on one of them and select Compare With > Each Other from the contextual menu. Eclipse will open a text compare window where the two files are shown side-by-side and any differences are highlighted and linked across the two views. Fix your code to remove any discrepancies between the correct output and your output.

Additional Activities

  1. Think about how you could automate testing of prettyPrint with JUnit. Write a JUnit test fixture to test Statement prettyPrint.