Lab 8: Post-Lab Assignment
Due Before Class Friday November 4th
Write a program to print a diamond-shaped pattern of stars (asterisks).
Your program should ask the user to enter the number of rows in
the top part of the diamond, then print the diamond (which will consist
of a triangle with the number of rows specified with a second "upside
down" triangle with one less row). For example, if the user enters
6 for the number of rows the program should print:
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
HINTS: You will need several nested for loops similar to the nested
loop in the Stars program on page 148 of the text. Note that in the
above diamond there is a blank space inbetween each star. You will need
to make adjustments to the loop control and other parts of the header
in the for loop to get the right number of stars printed. Also note
that you need to print some blank spaces before each row to "move"
the stars over. Printing blank spaces is just like printing the
asterisks - you need a loop. It would be a good idea to get the
top half right then add the bottom part of the diamond.
Requirements: As usual you must use good programming style and
document your program (including header documentation that describes
what the program does and includes your name, documentation on the
main method, and in-line documentation to mark the main sections of
code).
Other Requirements
- You must use meaningful names for variables, constants, and
your class. Use Java conventions for case -- constants (declared
with final) are all uppercase (with the underscore separating words),
variables start with a lowercase letter (but each separate word
within the variable starts with a capital), the class name is
capitalized.
Choosing meaningful names makes your program easier to read and follow.
- Use white space (blank lines and blank spaces) in your program to make
it easier to read. Separate the sections of the program with blank lines.
Indent and align your code properly.
- Document your program. At the top you must have documentation that
includes the file name, a brief description of
what the program does, the date, and your name.
Use in-line documentation to document each major section of code. However,
don't document every line!!
- See the following
code conventions for more detail about formatting
and documenting your program.
- Warning: A program that doesn't compile receives almost no credit
no matter how small the error.
Submission
To submit your code, create a zip file named YourLastName.zip and
upload the zip file to the course Inquire site.