Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions

Question

2. What should an employer do when facing an OSHA inspection?

Answered: 1 week ago