Using recursion, complete the body of the following Statement instance method. 1 2 3 4 5…
- User
Using recursion, complete the body of the following Statement instance method. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 /**
- Pretty prints {@code this} to the given stream {@code out} {@code offset}
- spaces from the left margin using
- {@link components.program.Program#INDENT_SIZE Program.INDENT_SIZE} spaces
- for each indentation level.
- @param out
-
the output stream - @param offset
-
the number of spaces to be placed before every nonempty line -
of output; nonempty lines of output that are indented further -
will, of course, continue with even more spaces - @updates out.content
- @requires out.is_open and 0 <= offset
- @ensures
- out.content =
- #out.content * [this pretty printed offset spaces from the left margin
-
using Program.INDENT_SIZE spaces for indentation]
*/ public void prettyPrint(SimpleWriter out, int offset) { switch (this.kind()) { case BLOCK: {
// TODO - fill in case break; } case IF: { // TODO - fill in case break; } case IF_ELSE: { // TODO - fill in case break; } case WHILE: { // TODO - fill in case break; } case CALL: { // TODO - fill in case break; } default: { // this will never happen... break; } }} Here is an example of what prettyPrint should output (with offset 0 from the left edge of the page): IF next-is-not-enemy THEN turnleft WHILE true DO IF random THEN move turnback IF next-is-not-wall THEN move END IF infect move ELSE go-for-it WHILE next-is-empty DO END WHILE turnleft turnright END IF END WHILE turnright skip skip-again END IF
- Assistant