Homework Solution: The top picture is the direction for the program. The second pictu…

    The top picture is the direction for the program. The second picture is what the program should look like once executed. Right below that is my program. I got it to print the Box, X and the diamond. I need to code to make it look like the example. For this assignment, you are to create a program in Java that asks the user to enter the size of a figure (must be odd), then displays a menu of 4 options. Options 1-3 will print various figures: box, diamond, X. Option 4 will allow the user to quit the program. You are to work on this assignment independently Program Design . You should have a single class called Figures . You will have 4 static methods: main, printBox, printDiamond, and printX. . The printBox,printDiamond, and printX methods should take as input an int parameter called size and print a box, diamond, or X shape respectively, of that given size. (see sample output at the end) 1. Ask the user to enter a number for the size of the figure. This number needs to be an ODD integer. If 2. Enter a loop in which you will display a menu of choices (1-4) and wait for user input (see example at . The main method should do the following the user enters a number that is not odd, ask him/her to reenter the number until it is odd. the end). The choices are: 1. Print box, 2. Print diamond, 3. Print X, and 4. Quit program If options 1-3 are selected, print the corresponding figure shape with dimensions-size × size, by calling the appropriate method. The exception is the diamond figure, which will have size rows and size+1 columns. See example for sample output. If option 4 is selected, quit the program and print Good bye! 3. 4. Additional Requirements The name of your Java Class that contains the main method should be Figures. All your code should be within a single file Your code should follow good coding practices, including good use of whitespace (indents and line breaks) and use of both inline and block comments You need to use meaningful identifier names that conform to standard Java naming conventions At the top of the file, you need to put in a block comment with the following information: your name, date, course name, semester, and assignment name. Your program needs to handle invalid inputs gracefully. For example, entering a number outside of a valid range should not crash the program. Instead, the user should be prompted to enter the number again. The output of your program should exactly match the sample program output given at the end 1. 2. 3. 4. 5. 6. import java.util.Scanner; public class newwpp { //declare and initialize instance variable public int size = 0; //method printBox public void printBox() { //loop that represents rows for(int i = 0; i < size ; i++) { //loop that represents columns for(int j = 0; j < size ; j++) { //print * System.out.print("*"); } //go to next line System.out.println(); } } public void printX() { for (int i = 1; i <= size; i++) { for (int j = 1; j <= size; j++) { if (j == i) { System.out.print("*"); } else if (j == size - (i - 1)) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(); } } public void printDiamond() { Scanner in = new Scanner (System.in); //System.out.print("Enter Number: "); int inp = in.nextInt(); int wan = 1; int space = inp ; for(int i = 0; i <inp ; i++) { for(int j = 0; j < space; j++) { System.out.print(" "); } for(int j = 0; j < wan ; j++) { if(j == 0 || j == wan -1) { System.out.print("*"); } else { System.out.print(" "); } } if(i == inp-1) { break; } else{ System.out.println(); wan=wan+2; space--; } } //second int x = (inp * 2) - 1; int y = 1; for(int l = 0; l < inp; l++) { for(int j = y; j >= 1; j--) { System.out.print(" "); } for(int j = 0; j < x ; j++) { if(l >= 1) { if(j == 0 || j == x - 1) { System.out.print("*"); } else { System.out.print(" "); } } } System.out.println(); x-=2; y++; } }   public static void main(String[] args) { int num = 9; Scanner scan = new Scanner(System.in);     while(num > 0 && num < 20) {System.out.print("Enter a odd number between (0 to 9): "); num= scan.nextInt();   if( num % 2 == 0) { System.out.println("Error. Please enter an odd number"); System.out.print("Enter a number between (1 to 9): "); num= scan.nextInt(); } else { System.out.println("You Enter: " + num); } //create an object for Box class newwpp myBox = new newwpp(); newwpp myX = new newwpp(); newwpp myDiamond = new newwpp(); //change the size to 5 using '.' operator myBox.size = num; myX.size = num; myDiamond.size = num; //invoke the printBox method myBox.printBox(); myX.printX(); myDiamond.printDiamond(); } }}
    For this assignment, you are to create a program in Java that asks the user to enter the size of a figure (must be odd), then displays a menu of 4 options. Options 1-3 will print various figures: box, diamond, X. Option 4 will allow the user to quit the program. You are to work on this assignment independently Program Design . You should have a single class called Figures . You will have 4 static methods: main, printBox, printDiamond, and printX. . The printBox,printDiamond, and printX methods should take as input an int parameter called size and print a box, diamond, or X shape respectively, of that given size. (see sample output at the end) 1. Ask the user to enter a number for the size of the figure. This number needs to be an ODD integer. If 2. Enter a loop in which you will display a menu of choices (1-4) and wait for user input (see example at . The main method should do the following the user enters a number that is not odd, ask him/her to reenter the number until it is odd. the end). The choices are: "1. Print box", "2. Print diamond", "3. Print X", and "4. Quit program" If options 1-3 are selected, print the corresponding figure shape with dimensions-size × size, by calling the appropriate method. The exception is the diamond figure, which will have size rows and size+1 columns. See example for sample output. If option 4 is selected, quit the program and print "Good bye!" 3. 4. Additional Requirements The name of your Java Class that contains the main method should be Figures. All your code should be within a single file Your code should follow good coding practices, including good use of whitespace (indents and line breaks) and use of both inline and block comments You need to use meaningful identifier names that conform to standard Java naming conventions At the top of the file, you need to put in a block comment with the following information: your name, date, course name, semester, and assignment name. Your program needs to handle invalid inputs gracefully. For example, entering a number outside of a valid range should not crash the program. Instead, the user should be prompted to enter the number again. The output of your program should exactly match the sample program output given at the end 1. 2. 3. 4. 5. 6.

    Expert Answer

     
    Figures.java: import java.util.Scanner;

    The apex draw is the control ce the program. The cooperate draw is what the program should behold affect unintermittently produced. Right adown that is my program. I got it to imimimsculpture the Smack, X and the diamond. I insufficiency to mode to gain it behold affect the model.

    Ce this enactment, you are to controlm a program in Java that entreats the representationr to penetrate the bulk of a symbol (must be remaining), then shows a menu of 4 libertys. Libertys 1-3 accomplish imimimsculpture different symbols: smack, diamond, X. Liberty 4 accomplish confess the representationr to abandon the program. You are to production on this enactment inconsequently Program Design . You should accept a individual tabulate determined Symbols . You accomplish accept 4 static ways: deep, imprintBox, imprintDiamond, and imprintX. . The imprintBox,printDiamond, and imprintX ways should assume as inarconcatenate an int parameter determined bulk and imimimsculpture a smack, diamond, or X cast respectively, of that absorbed bulk. (attview case quenchedarconcatenate at the view) 1. Entreat the representationr to penetrate a compute ce the bulk of the symbol. This compute insufficiencys to be an ODD integer. If 2. Penetrate a loop in which you accomplish show a menu of excellents (1-4) and hold ce representationr inarconcatenate (attview model at . The deep way should do the restraintthcoming the representationr penetrates a compute that is referable remaining, entreat him/her to repenetrate the compute until it is remaining. the view). The excellents are: 1. Imimsculpture smack, 2. Imimsculpture diamond, 3. Imimsculpture X, and 4. Abandon program If libertys 1-3 are separated, imimimsculpture the similar symbol cast with dimensions-bulk × bulk, by avocation the withhold way. The exclusion is the diamond symbol, which accomplish accept bulk rows and bulk+1 columns. Attview model ce case quenchedput. If liberty 4 is separated, abandon the program and imimimsculpture Cheerful-natured-natured bye! 3. 4. Additional Requirements The indicate of your Java Tabulate that contains the deep way should be Symbols. All your mode should be among a individual finish Your mode should flourish cheerful-natured-natured coding practices, including cheerful-natured-natured representation of whitemeasure (indents and cord breaks) and representation of twain incord and obstruct illustrates You insufficiency to representation meaningful identifier indicates that yield to banner Java naming conventions At the apex of the finish, you insufficiency to arconcatenate in a obstruct illustrate with the restraintthcoming information: your indicate, bound, series indicate, semester, and enactment indicate. Your program insufficiencys to treat infirm inputs gracefully. Ce model, penetrateing a compute beyond of a conclusive concatenate should referable resonance the program. Instead, the representationr should be prompted to penetrate the compute repeatedly. The quenchedarconcatenate of your program should precisely equal the case program quenchedarconcatenate absorbed at the view 1. 2. 3. 4. 5. 6.

    import java.util.Scanner;

    public tabulate novellightlightwpp

    {

    //approve and initialize entreaty variable

    public int bulk = 0;

    //way imprintBox

    public null imprintBox()

    {

    //loop that represents rows

    for(int i = 0; i < bulk ; i++)

    {

    //loop that represents columns

    for(int j = 0; j < bulk ; j++)

    {

    //imimsculpture *

    System.out.print(“*”);

    }

    //go to proximate cord

    System.out.println();

    }

    }

    public null imprintX()

    {

    ce (int i = 1; i <= bulk; i++) {

    ce (int j = 1; j <= bulk; j++) {

    if (j == i) {

    System.out.print(“*”);

    } else if (j == bulk – (i – 1)) {

    System.out.print(“*”);

    } else {

    System.out.print(” “);

    }

    }

    System.out.println(); }

    }

    public null imprintDiamond()

    {

    Scanner in = novellightlightlight Viewner (System.in);

    //System.out.print(“Penetrate Compute: “);

    int inp = in.nextInt();

    int wan = 1;

    int measure = inp ;

    for(int i = 0; i <inp ; i++)

    {

    for(int j = 0; j < measure; j++)

    {

    System.out.print(” “);

    }

    for(int j = 0; j < wan ; j++)

    {

    if(j == 0 || j == wan -1)

    {

    System.out.print(“*”);

    }

    else

    {

    System.out.print(” “);

    }

    }

    if(i == inp-1)

    {

    break;

    }

    else{

    System.out.println();

    wan=wan+2;

    space–;

    }

    }

    //second

    int x = (inp * 2) – 1;

    int y = 1;

    for(int l = 0; l < inp; l++)

    {

    for(int j = y; j >= 1; j–)

    {

    System.out.print(” “);

    }

    for(int j = 0; j < x ; j++)

    {

    if(l >= 1)

    {

    if(j == 0 || j == x – 1)

    {

    System.out.print(“*”);

    }

    else

    {

    System.out.print(” “);

    }

    }

    }

    System.out.println();

    x-=2;

    y++; }

    }

     

    public static null deep(String[] args)

    { int num = 9;

    Scanner view = novellightlightlight Viewner(System.in);

     

     

    while(num > 0 && num < 20)

    {System.out.print(“Penetrate a remaining compute betwixt (0 to 9): “);

    num= view.nextInt();

     

    if( num % 2 == 0)

    {

    System.out.println(“Error. Please penetrate an remaining compute”);

    System.out.print(“Penetrate a compute betwixt (1 to 9): “);

    num= view.nextInt();

    }

    else

    {

    System.out.println(“You Penetrate: ” + num);

    }

    //form an view ce Smack tabulate

    newwpp mySmack = novellightlightlight novellightlightwpp();

    newwpp myX = novellightlightlight novellightlightwpp();

    newwpp myDiamond = novellightlightlight novellightlightwpp();

    //change the bulk to 5 using ‘.’ operator

    myBox.bulk = num;

    myX.bulk = num;

    myDiamond.bulk = num;

    //invoke the imprintSmack way

    myBox.printBox();

    myX.printX();

    myDiamond.printDiamond();

    }

    }}

    Ce this enactment, you are to controlm a program in Java that entreats the representationr to penetrate the bulk of a symbol (must be remaining), then shows a menu of 4 libertys. Libertys 1-3 accomplish imimimsculpture different symbols: smack, diamond, X. Liberty 4 accomplish confess the representationr to abandon the program. You are to production on this enactment inconsequently Program Design . You should accept a individual tabulate determined Symbols . You accomplish accept 4 static ways: deep, imprintBox, imprintDiamond, and imprintX. . The imprintBox,printDiamond, and imprintX ways should assume as inarconcatenate an int parameter determined bulk and imimimsculpture a smack, diamond, or X cast respectively, of that absorbed bulk. (attview case quenchedarconcatenate at the view) 1. Entreat the representationr to penetrate a compute ce the bulk of the symbol. This compute insufficiencys to be an ODD integer. If 2. Penetrate a loop in which you accomplish show a menu of excellents (1-4) and hold ce representationr inarconcatenate (attview model at . The deep way should do the restraintthcoming the representationr penetrates a compute that is referable remaining, entreat him/her to repenetrate the compute until it is remaining. the view). The excellents are: “1. Imimsculpture smack”, “2. Imimsculpture diamond”, “3. Imimsculpture X”, and “4. Abandon program” If libertys 1-3 are separated, imimimsculpture the similar symbol cast with dimensions-bulk × bulk, by avocation the withhold way. The exclusion is the diamond symbol, which accomplish accept bulk rows and bulk+1 columns. Attview model ce case quenchedput. If liberty 4 is separated, abandon the program and imimimsculpture “Good-natured bye!” 3. 4. Additional Requirements The indicate of your Java Tabulate that contains the deep way should be Symbols. All your mode should be among a individual finish Your mode should flourish cheerful-natured-natured coding practices, including cheerful-natured-natured representation of whitemeasure (indents and cord breaks) and representation of twain incord and obstruct illustrates You insufficiency to representation meaningful identifier indicates that yield to banner Java naming conventions At the apex of the finish, you insufficiency to arconcatenate in a obstruct illustrate with the restraintthcoming information: your indicate, bound, series indicate, semester, and enactment indicate. Your program insufficiencys to treat infirm inputs gracefully. Ce model, penetrateing a compute beyond of a conclusive concatenate should referable resonance the program. Instead, the representationr should be prompted to penetrate the compute repeatedly. The quenchedarconcatenate of your program should precisely equal the case program quenchedarconcatenate absorbed at the view 1. 2. 3. 4. 5. 6.

    Expert Exculpation

     

    Figures.java:

    import java.util.Scanner;

    public tabulate Symbols {

    static Viewner view = novellightlightlight Viewner(System.in);

    // approve and initialize entreaty variable

    public int bulk = 0;

    public Symbols(int bulk) {

    this.bulk = bulk;

    }

    // way imprintBox

    public null imprintBox() {

    // loop that represents rows

    ce (int i = 0; i < bulk; i++) {

    // loop that represents columns

    ce (int j = 0; j < bulk; j++) {

    System.out.print(“X”);

    }

    // go to proximate cord

    System.out.println();

    }

    System.out.println();

    }

    public null imprintX() {

    ce (int i = 1; i <= bulk; i++) {

    ce (int j = 1; j <= bulk; j++) {

    if (j == i) {

    System.out.print(“X”);

    } else if (j == bulk – (i – 1)) {

    System.out.print(“X”);

    } else {

    System.out.print(” “);

    }

    }

    System.out.println();

    }

    System.out.println();

    }

    public null imprintDiamond() {

    int wan = 1;

    int measure = bulk;

    ce (int i = 0; i < bulk; i++) {

    ce (int j = 0; j < measure; j++) {

    System.out.print(” “);

    }

    ce (int j = 0; j < wan; j++) {

    if (j == 0 || j == wan – 1) {

    System.out.print(“*”);

    } else {

    System.out.print(” “);

    }

    }

    if (i == bulk – 1) {

    break;

    } else {

    System.out.println();

    wan = wan + 2;

    space–;

    }

    }

    // cooperate

    int x = (bulk * 2) – 1;

    int y = 1;

    ce (int l = 0; l < bulk; l++) {

    ce (int j = y; j >= 1; j–) {

    System.out.print(” “);

    }

    ce (int j = 0; j < x; j++) {

    if (l >= 1) {

    if (j == 0 || j == x – 1) {

    System.out.print(“*”);

    } else {

    System.out.print(” “);

    }

    }

    }

    System.out.println();

    x -= 2;

    y++;

    }

    System.out.println();

    }

    private static int getChoice() {

    System.out.println(“1. Imimsculpture Smack.”);

    System.out.println(“2. Imimsculpture Diamond.”);

    System.out.println(“3. Imimsculpture X.”);

    System.out.println(“4. Abandon.”);

    int excellent = view.nextInt();

    while(excellent < 1 || excellent > 4) {

    System.out.print(“Infirm excellent. Try repeatedly: “);

    excellent = view.nextInt();

    }

    return excellent;

    }

    public static null deep(String[] args) {

    int num;

    while (true) {

    System.out.print(“Penetrate a remaining compute betwixt (0 to 9): “);

    num = view.nextInt();

    if (num % 2 == 0 || num <= 0 || num > 9) {

    System.out.println(“Error. Please penetrate an remaining compute”);

    } else {

    System.out.println(“You Penetrateed: ” + num);

    break;

    }

    }

    // controlm an view ce symbol tabulate

    Figures symbol = novellightlightlight Symbols(num);

    int excellent = getChoice();

    while(excellent != 4) {

    switch(choice) {

    case 1:

    figure.printBox();

    break;

    case 2:

    figure.printDiamond();

    break;

    case 3:

    figure.printX();

    break;

    }

    excellent = getChoice();

    }

    System.out.println(“Thank-You.”);

    }

    }