Ice15-Part 1 Part 1: Nested Loops and Non-Robotic Programs

Note:  Please keep the programs that you create today, in case you have a question about your grades for the ICEs at the end of the quarter. When you're working with a partner, each person should save his-or-her own copy.

ICEICE 16.1.1: Printing a Hollow Rectangle with a Method (Sub-Command)

For this part, you should add a method to your PrintHelper class from the previous ICE and name it it PrintRectangleHollow(). You can use this PrintingShapesRec.java file for this ICE if you don't have yours.

The PrintRectangleHollow() methods should have the exact same parameters as PrintRectangle(), and should function similarly, except that any 'interior' spaces should be filled with blank spaces, not asterisks. SEE THE HINTS BELOW.

Thus, the following code snippets should generate the following output:

// This:
helper.PrintRectangleHollow(3, 5);
// Outputs this:
// ***
// * *
// * *
// * *
// ***

// This:
helper.PrintRectangleHollow(5, 5);
// Outputs this:
// *****
// *   *
// *   *
// *   *
// *****

// This:
helper.PrintRectangleHollow(2, 2);
// Outputs this:
// **
// **

// This:
helper.PrintRectangleHollow(5, 1);
// Outputs this:
// *****

NoteNote: Printing a box with a 'hollow' center is really done with a bit of coding smoke-and-mirrors. This means that while the finished product that is printed out certainly looks like a box, in the code it isn't really a box at all, but three distinct sections that are 'stacked' upon each other:

A 'top' row:

*****

Some 'middle' rows that contain a 'star', some spaces, and another 'star':

*   *
*   *
*   *

A 'bottom' row:

*****

Putting them all together, the number of characters in all the rows will be the same. For example, the 'top' and 'bottom' rows will each have 5 stars, and the 'middle' rows will have 2 stars and 3 spaces. Figuring out the logic to printing out the 'top' and 'bottom' rows is relatively easy, however the logic for printing out the 'middle' rows is a bit trickier. I recommend you treat the left-hand and right-hand stars as separate print processes, and concentrate on the logic needed to put the spaces between them. For example, if a row consists of 5 characters, then the number of spaces between the left-hand and right-hand stars will be 3. What logic might you use to determine the number of spaces between the left-hand and right-hand stars no matter what the number of characters in each row (whether 5, or 10, or 15)?.

ICEICE 16.1.2: Printing a Left Triangle

For this part, you should add a method to your PrintHelper class, named PrintLeftTriangle().

This should have only a single parameter, height, which is an integer.

This method will print out a 'triangle', with a straight vertical edge long the left side of the screen:

// This:
helper.PrintLeftTriangle(5);
// Outputs:
// *****
// ****
// ***
// **
// *

// This:
helper.PrintLeftTriangle(3);
// Outputs:
// ***
// **
// *

// This:
helper.PrintLeftTriangle(2);
// Outputs:
// **
// *

When you get done with this exercise, show your Instructor.