Question
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started