Question: /*************************************************** * Project Assignment 3: DrawDiamond_Project3.java * * Program draws a diamond using chosen charactor * * * * Created by your NO NAME, March

/*************************************************** * Project Assignment 3: DrawDiamond_Project3.java * * Program draws a diamond using chosen charactor * * * * Created by your NO NAME, March 3, 2018 * ***************************************************/ import java.util.Scanner; public class DrawDiamond_Project3 { public static void main( String args[] ) { int size; // size of the diamond, i.e. # of charactor at diagonal, or # of rows, or # of columns char ch; // charactor used to draw the diamond Scanner input = new Scanner( System.in ); /* TODO: write code to request input for size of the diamond and check input validation */ /* TODO: write code to request input for the charactor to draw the diamond */ /* TODO: write code to create an object of class Diamond_Project3 */ Diamond_Project3 aDiamond = new Diamond_Project3( size, ch ); /* TODO: write code to draw this diamond by calling some method of Diamond_Project3 */ } // end main } // end class DrawDiamond_Project3 /************************************************************************* * Project Assignment 3: Diamond_Project3.java * * Diamond class with constructors initialize the diamond size/charactor * * * * Created by your NO NAME, March 3, 2018 * *************************************************************************/ public class Diamond_Project3 { private int diamondSize; // size of the diamond, i.e. # of charactor at diagonal, or # of rows, or # of columns private char diamondChar; // charactor used to draw the diamond // constructor initializes both diamond size and diamond charactor public Diamond_Project3( int size, char ch ) { diamondSize = size; diamondChar = ch; } // end constructor // method to set the diamond size public void setDiamondSize( int size ) { diamondSize = size; // store the diamond size } // end method setDiamondSize // method to retrieve the diamond size public int getDiamondSize() { return diamondSize; } // end method getDiamondSize // method to set the diamond charactor public void setDiamondChar( int size ) { diamondSize = size; // store the diamond charactor } // end method setDiamondChar // method to retrieve the diamond charactor public int getDiamondChar() { return diamondChar; } // end method getDiamondChar // method to draw a diamond with the given size (diamondSize) using for loop public void drawADiamond() { int i, j; int rows = diamondSize / 2; //# of rows for the top triangle or the bottom triangle int nSpaces, nChars; //# of white spaces or asterisks to print each row /* TODO: write code to draw the top triangle */ //draw the middle line for ( i = 0; i < diamondSize; i++ ) { System.out.print( diamondChar ); } System.out.println(); //print a newline /* TODO: write code to draw the bottom triangle */ } // end drawADiamond } // end class Diamond_Project3 Problem Description Write a Java program that displays the following pattern. Use for loops to generate the patterns. All chosen character should be printed by a single statement of the form System.out.print( chosenChar ); //chosenChar is a char type variable, the value input by user With this statement in a loop it causes the chosen character to print side by side. A statement of the following form can be used to move to the next line. System.out.println(); A statement of the following form can be used to display a space. There should be no other output statements in the program. System.out.print( ); Problem-Solving Tips 1. The diamond could be split into three parts: the top triangle, the middle line (the number of characters is the size of the diamond), and the bottom triangle. 2. For the top and bottom triangles, you should decide how many white spaces to print before the first character and how many characters to print. Use nested for loops: outer for loop is for rows, two inner for loops, one to print white spaces, one to print characters. 3. Use a for loop for the middle line (the code has been given). 4. If you have any questions as you proceed, ask your lab instructor for help.

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!