Course: Introduction to Computers & Programming (JAVA), Summer 2009
Instructor: Christopher Conway

Homework #4

Due: Sunday, 14 June 2009 at 11:59 PM

Kilims are woven rugs which generally use symmetrical designs. For this assignment, instead of using a loom, wool, and a shuttle, you should produce the following pattern using "for" loops and nested "for" loops.

Here is the pattern:

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

The entire design is made up of stars (asterisks) and spaces.

The output of your program should EXACTLY match the pattern above.


Hints:


Extra Credit (5 points):

Extend your program so that it can "tile" rugs horizontally and vertically by reproducing the pattern above. Ask the user for the desired width (i.e., number of rugs across) and height (i.e., number of rugs down).

Your program should not crash or produce unexpected output if the user inputs a non-integer. Instead it should re-prompt the user for a valid input.

Example. If the input is
Enter a width: 3
Enter a height: 2
your program should produce the following output:
*********************************************************************************
*********************************************************************************
***   ***   ***   ***   ******   ***   ***   ***   ******   ***   ***   ***   ***
   ***   ***   ***   ***      ***   ***   ***   ***      ***   ***   ***   ***   
***   ***   ***   ***   ******   ***   ***   ***   ******   ***   ***   ***   ***
   ***   ***   ***   ***      ***   ***   ***   ***      ***   ***   ***   ***   
             *                          *                          *             
            ***                        ***                        ***            
           *****                      *****                      *****           
          *******                    *******                    *******          
         *********                  *********                  *********         
          *******                    *******                    *******          
           *****                      *****                      *****           
            ***                        ***                        ***            
             *                          *                          *             
***   ***   ***   ***   ******   ***   ***   ***   ******   ***   ***   ***   ***
   ***   ***   ***   ***      ***   ***   ***   ***      ***   ***   ***   ***   
***   ***   ***   ***   ******   ***   ***   ***   ******   ***   ***   ***   ***
   ***   ***   ***   ***      ***   ***   ***   ***      ***   ***   ***   ***   
*********************************************************************************
*********************************************************************************
*********************************************************************************
*********************************************************************************
***   ***   ***   ***   ******   ***   ***   ***   ******   ***   ***   ***   ***
   ***   ***   ***   ***      ***   ***   ***   ***      ***   ***   ***   ***   
***   ***   ***   ***   ******   ***   ***   ***   ******   ***   ***   ***   ***
   ***   ***   ***   ***      ***   ***   ***   ***      ***   ***   ***   ***   
             *                          *                          *             
            ***                        ***                        ***            
           *****                      *****                      *****           
          *******                    *******                    *******          
         *********                  *********                  *********         
          *******                    *******                    *******          
           *****                      *****                      *****           
            ***                        ***                        ***            
             *                          *                          *             
***   ***   ***   ***   ******   ***   ***   ***   ******   ***   ***   ***   ***
   ***   ***   ***   ***      ***   ***   ***   ***      ***   ***   ***   ***   
***   ***   ***   ***   ******   ***   ***   ***   ******   ***   ***   ***   ***
   ***   ***   ***   ***      ***   ***   ***   ***      ***   ***   ***   ***   
*********************************************************************************
*********************************************************************************

If the input is

Enter a width: Mxyzptlk
the program should respond
Not a valid width: Mxyzptlk
Enter a width:
and so on.

NOTE: A single line may not be wide enough to display more than 2 or 3 rugs across.


Style counts:

Your assignment should be submitted BY EMAIL to our class grader: Andrew Lott, adl316 (AT) nyu (DOT) edu.

Last modified: 09 Jun 2009