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
- First carefully look through the file
Statement1PrettyPrint1.java, which is an extension forStatement1that overrides theStatementSecondaryimplementation of theprettyPrintmethod, and make sure that you familiarize yourself with the methods provided. Note that it includes amainmethod used to test the implementation ofprettyPrint. - In
Statement1PrettyPrint1.java, complete the body of theprettyPrintinstance method by pasting the code you wrote for the homework. Here are a few things to keep in mind:- The contract for
prettyPrintis informal and vague. To see what the output ofprettyPrintis supposed to look like, open theSampleStatement.blfile in thedatafolder. Your implementation ofprettyPrintmust generate this output if called on theStatementobject corresponding to the SampleStatement BL statement (with indentation 0 from the left edge of the page). prettyPrintmust restore the value ofthis.- Your solution has to be recursive.
- The contract for
- When you have completed the implementation of
prettyPrint, run theStatement1PrettyPrint1test program. You can use theSampleStatement.blfile in thedatafolder in your project as a test input. The main program generates two output files (both in thedatafolder):expected-output.txtthat contains the correct output for the given program andactual-output.txtthat is the output generated by your implementation. Eclipse provides a convenient way of comparing files. In the Package Explorer view, open thedatafolder 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
- Think about how you could automate testing of
prettyPrintwith JUnit. Write a JUnit test fixture to testStatementprettyPrint.