Program Rectangle solution

$30.00

Description

File Name:

H:\CPSC1150\Lab3\Rectangle.java

Purpose

To create a rectangle in a 40×20 grid

Input

Initial x and y coordinates, and the height and width of the rectangle.

Output

A grid with a rectangle starting at the right coordinates with the correct height and width

Program Logic (Pseudocode) Solution

Algorithm Rectangle

Start

1. Initialize variables

(a) x-coord (input) in int

(b) y-coord (input) in int

(c) height (input) in int

(d) width (input) in int

(e) xaxis (constant) in int

(f) yaxis (constant) in int

2. Get user to give valid values for (a,b,c, and d)

(a) make sure it fits in the grid

(b) make sure height and width don’t go out of grid

3. Create Loop for the y-axis

(a) if statements for values divisible by 5

4. Create Loop for x-axis

(a) if statements for values divisible by 5

5. Create loops for the width of the rectangle

(a) first loop to add spaces for values before the x-coord

(b) second loop to add stars for how wide the rectangle is

6. Create the height the rectangle by going into the loop created in step 3

(a) set if statements to make sure the rectangle starts at the right y-coord

(b) set an if statement with conditions to make sure the height is correct

for the rectangle

7. Test and hand in