Lab14: Practice with nested loops
Background
In the good old days, we didn't have fancy computer graphics. So we had to rely on ASCII art and the user's imagination. Today's lab will take you back in time! Your task is to draw various pictures of stars ('*') that require the creative use of iteration and decisions.
Collaboration: You are encouraged to work with another student to complete this lab. Each of you should submit your own copy of the programs. It's okay if your files are similar or identical, as long as both of your names are present at the top.
Objectives
Instructions
Pattern A
********** ********* ******** ******* ****** ***** **** *** ** *
The leftmost stars are in the leftmost output column. Test your code with an odd number of stars and an even number of stars.
HINT: While developing the code, replace each space with another character that is visible.
Pattern B
* ** *** **** ***** ****** ******* ******** ********* **********
The leftmost star of the last row is in the first position of the output column.
HINT: You used starCnt in the original example and Pattern A. You should think about using the blnkCnt variable as well.
Pattern C
********** ********* ******** ******* ****** ***** **** *** ** *
The top row, leftmost star is in the first position of the output.
HINT: It should be the same as Pattern B, except for the way you calculate blnkCnt and starCnt.
Expeected value file for diff testing lab12extra.exp.
GeneralizationSubmit Stars.java via Autolab by 11pm on the day after the lab . If you finish early, work the extra credit section for extra point on the submission.
Pattern D (Extra Credit)
* *** ***** ******* ********* ******* ***** *** *
For an odd number of rows, you would only have one middle line. The middle row leftmost star is in the first position of the output.
HINT: Consider writing two loops: one for the top half, and another for the bottom half. You may also want to increment and decrement starCnt and blnkCnt, rather than calculate them directly based on the row number.