Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3) Write a program that takes an input letter and outputs it in a diamond shape. Given a letter, it prints a diamond starting with

3) Write a program that takes an input letter and outputs it in a diamond shape. Given a letter, it prints a diamond starting with 'A', with the supplied letter at the widest point.

Your program should satisfy the following requirements:

The first row contains one 'A'

. The last row contains one 'A'

. All rows, except the first and last, have exactly two identical letters.

The diamond is horizontally symmetric.

The diamond is vertically symmetric.

The diamond has a square shape (width equals height).

The letters form a diamond shape.

The top half has the letters in ascending order.

The bottom half has the letters in descending order.

a) Examples In the following examples, spaces are indicated by character ..

i) Example 1 Diamond for letter 'A':

A

ii) Example 2 Diamond for letter 'C':

..A..

.B.B.

C...C

.B.B.

..A..

iii) Example 3 Diamond for letter 'E':

....A....

...B.B...

..C...C..

.D.....D

. E.......E

.D.....D.

..C...C..

...B.B...

....A....

Your program must have the following methods:

b) public static void main(String[] args)

Main method will take the input letter from the user.

Then, it will invoke the method constructDiamond() .

Lastly, it will invokethe method printDiamond().

c) public static char[][] constructDiamond (char letter)

This method should take a char letter and construct the diamond shape for the given letter in a two dimensional char array.

The size of your two dimensional array is determined based on the given letter.

This method should return the two dimensional array to the main() method.

d) public static void printDiamond (char[][] diamond)

This method should take a two dimensional char array and print the content of it.

e) Sample Runs

i) Sample Run 1

Enter a Letter:7

Invalid Input !

ii) Sample Run 2

Enter a Letter:

* Invalid Input !

iii) Sample Run 3

Enter a Letter: A

A

iv) Sample Run 4

Enter a Letter:C

..A..

.B.B.

C...C

.B.B.

A

please you write new code do not use reuse

I WILL BE VERY HAPPY IF YOU TRY TO WRITE A BEGINNING-LEVELS JAVA ( ECLIPSE ) CODE. DO NOT USE A CLASS OUTSIDE THE SCANNER CLASS ( import.util.Scanner ) SO ( do not use import java.util.Collections , etc imort java.io

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

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

What are the various designations associated with HRM?

Answered: 1 week ago

Question

What are the objectives of job evaluation ?

Answered: 1 week ago

Question

Write a note on job design.

Answered: 1 week ago

Question

Compute the derivative of f(x)cos(-4/5x)

Answered: 1 week ago

Question

Discuss the process involved in selection.

Answered: 1 week ago