Question: Write a program that displays diamonds and hollow diamonds as text using a character provided by the user. For example, a diamond and a hollow

Write a program that displays diamonds and hollow diamonds as text using a character provided by the user. For example, a diamond and a hollow diamond of height 6 constructed from asterisks will display as follows:(ignore the periods)

.....*

...***

.*****

.*****

...***

....*

.....*

...*....*

.*.........*

.*.........*

...*.....*

......*

Besides specifying a character, the user will specify one of three possible heights for each diamond 6, 12, or 24 by providing one of the strings short, average, or tall.

Write the following methods in the program:

Public static int checkSize(String size) This method will return 6 if size equals short, 12 if size equals average, 24 if size equals tall, or -1 otherwise. Be sure that the comparison is not case sensitive.

Public static void displayDiamond (int size, char ch) This method will display a diamond of height size constructed from pattern character ch.

Public static void displayHollowDiamond (int size, char ch) This method will display a hollow diamond of height size constructed from pattern character ch.

Call the method checkSize() in a do-while loop in the main method to verify that the diamond size that user enters must be short, average, or tall. If invalid string is input, checkSize()will return -1 and the program should ask for new input until the valid input is given.

The following are examples of the required I/O behavior:

enter diamond size ("short", "average", or "tall"): unknown

enter diamond size ("short", "average", or "tall"): -1 enter diamond size ("short", "average", or "tall"): 6

enter diamond size ("short", "average", or "tall"): 12 enter diamond size ("short", "average", or "tall"): average

enter pattern character: $

..........$

........$$$

......$$$$$

....$$$$$$$

..$$$$$$$$$

$$$$$$$$$$$

$$$$$$$$$$$

..$$$$$$$$$

....$$$$$$$

......$$$$$

........$$$

..........$

..........$

........$...$

.......$......$

.....$..........$

...$.............$

.$ ................$

.$ ................$

...$.............$

.....$.........$

.......$......$

........$...$

..........$

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!