CS 161

Lab #3

Due Monday, February 16, Classtime

 

You are to write a program to print out the 8 figures shown below in the sample output.

Requirements

1.      Name the project Lab3

2.      Name the class Figures

3.      Use a class constant to indicate the size of each figure. In the sample output below, the size used was 5.

4.      Each figure should be drawn with its own method.

5.      The output should have a blank line between each of the figures...there are no other blank lines in any of the figures.

6.      The main method should call the 8 drawing methods. Output the blank line between figures from the main method.

7.      In the code, you should separate the code of each method with a blank line, then a comment containing a line of dashes before each method header.

8.      Don't forget the header comments at the top of the code to indicate your name, the class and section, and the date.

9.      The methods should be called line( ), slantRight( ), slantLeft( ), square( ), rectangle( ), box( ), pyramid( ), and diamond( ).

10.  The square doesn't look square because of the way asterisks and lines are spaced...it is square in the sense that it is 5 asterisks wide and 5 asterisks tall.

11.  The rectangle figure is three times as high as it is wide.

12.  You should use loops to print out all of these figures, and each line of the figure. NONE of the print or println statements in the entire program should print more than one character at a time, either a blank (" ") or an asterisk ("*").

Hints

1.      Two of the methods can be called by other methods to remove the need for redundant code...which ones?

2.      For the pyramid and diamond figures, the table method (from your book) for figuring out loop expressions is very useful.

3.      The diamond figure code is easier if one of the loops counts backwards.

4.      Code one figure at a time and get it to work...don't try to code them all at once. If you get stuck on one of the figures, move on to the next figure and come back later to the one that you didn't get working.

Sample Output

*****

    *
   *
  *
 *
*

*
 *
  *
   *
    *

*****
*****
*****
*****
*****

*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****

*****
*   *
*   *
*   *
*****

    *
   ***
  *****
 *******
*********

    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *

Submission

Submit this program as Lab3.