Answered You can hire a professional tutor to get the answer.

QUESTION

Parts2-5 Nested Loops Non-robotic Programs Part 2 : Printing A Rectangle NOTE: Don't use arrays for the rest of this ICE. Download the file named...

Parts2-5 Nested Loops & Non-robotic Programs 

Part 2: Printing A Rectangle

NOTE: Don't use arrays for the rest of this ICE.

Download the file named PrintingShapes.java from the website. For this part, you should use the non-Robotic class, named PrintHelper. This class will serve the purpose of holding a bunch of commands (methods) that print things out. Using this as a basis, finish the code for PrintHelper's printRectangle method that will print out a rectangle of asterisks, using for-loops (yes, they have to be nested). The output of a call to printer.printRectangle(5, 3); should look like so:

*****

*****

*****

Part 3: Printing A Hollow Rectangle, Via A Subcommand

For this part, you should add a method to your PrintHelper class, named printRectangleHollow. This 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. Thus, the following code snippets should generate the following output:

 // This:

printer.printRectangleHollow(3, 5);

// Outputs this:

//  ***

//  * *

//  * *

//  * *

//  ***

// This:

printer.printRectangleHollow(4, 5);

// Outputs this:

//  ****

//  * *

//  * *

//  * *

//  ****

// This:

printer.printRectangleHollow(2, 2);

// Outputs this:

//  **

//  **

// This:

printer.printRectangleHollow(5, 1);

// Outputs this:

//  *****

Part 4: Printing A Left Triangle, Via A Subcommand

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:

printer.printLeftTriangle(5);

// Outputs

// *****

// ****

// ***

// **

// *

// This:

printer.printLeftTriangle(3);

// Outputs

// ***

// **

// *

// This:

printer.printLeftTriangle(2);

// Outputs

// **

// *

Part 5: Adding user input

Now add some code that will first ask the user the width and/or height of each shape and then it will print the shape out. You must use each Print Helper method at least once. An example transcript of the program might look like is below.

      If you want to print some text, and move to the next line (like you normally want to), then you use

System.out.println(""); // print nothing, but move to the next line!

If you want to print some text, without moving to the next line, you use

System.out.print("*"); // note that it's print , not println

Example Partial Transcript(user input in bold):

Hello! How many stars would you like me to print?

5

Stars:

*****

For a rectangle, how wide should it be?

5

For a rectangle, how high should it be?

3

Rectangle:

*****

*****

*****

public class NestedFor {

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question