CSCI 220 Homework Assignment #4

Assigned Date: Monday, February 24, 2003 
Due Date: Friday, February 28, 2003 
Due Time: Noon 

Updated: Monday, February 24, 2003 10:51 AM

Program file name to be submitted: DrawRectangle.java

Skills Developed: Iteration, Selection structures, Error Checking.

Purpose: This assignment asks you to write Java code to create a hollow rectangle. You will practice Java syntax, reading input from the user, using repetition structures, and output.

Specifications: Write a Java program to print out a rectangle formed by the '*' character. The program must ask the user to enter the height and width of the rectangle and output the appropriate shape. The program must use a loop to guarantee that the height and width entered by the user are positive numbers. Also the program must guarantee that the width is not greater than 60. See the example outputs below:

Sample Run #1:

Enter a positive integer less than 60 for the width of the rectangle: -1

-1 is not positive.

Enter a positive integer less than 60 for the width of the rectangle: -57

-57 is not positive.

Enter a positive integer less than 60 for the width of the rectangle: 62

62 is not less than 60.

Enter a positive integer less than 60 for the width of the rectangle: 6

Enter a positive integer for the height of the rectangle: -12

-12 is not positive.

Enter a positive integer for the height of the rectangle: 4

Here is your rectangle:

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

 

Sample Run #2:

Enter a positive integer less than 60 for the width of the rectangle: 1

Enter a positive integer for the height of the rectangle: 1

Here is your rectangle:

*