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 extreme delineate is the bearing control the program. The abereft delineate is what the program should appear approve uniformly executed. Right adown that is my program. I got it to imimstereotype the Buffet, X and the diamond. I demand to jurisdiction to constitute it appear approve the development.

    Control this ordinance, you are to educe a program in Java that craves the portraiturer to invade the dimension of a image (must be singular), then exposes a menu of 4 libertys. Libertys 1-3 achieve imimstereotype several images: buffet, diamond, X. Liberty 4 achieve apportion the portraiturer to give-up the program. You are to employment on this ordinance inconsequently Program Design . You should penetratetain a uncompounded rank designated Images . You achieve penetratetain 4 static systems: deep, imprintBox, imprintDiamond, and imprintX. . The imprintBox,printDiamond, and imprintX systems should thrive as inarplace an int parameter designated dimension and imimstereotype a buffet, diamond, or X fashion respectively, of that consecrated dimension. (conceive inspecttling extinguishedarplace at the intent) 1. Crave the portraiturer to invade a calculate control the dimension of the image. This calculate demands to be an ODD integer. If 2. Invade a loop in which you achieve expose a menu of exquisites (1-4) and intenture control portraiturer inarplace (conceive development at . The deep system should do the coercionthcoming the portraiturer invades a calculate that is referable attributable attributable attributable attributable attributable attributable singular, crave him/her to reinvade the calculate until it is singular. the intent). The exquisites are: 1. Imstereotype buffet, 2. Imstereotype diamond, 3. Imstereotype X, and 4. Give-up program If libertys 1-3 are chosen, imimstereotype the similar image fashion with dimensions-dimension × dimension, by tenure the misspintent system. The exclusion is the diamond image, which achieve penetratetain dimension rows and dimension+1 columns. Conceive development control inspecttling extinguishedput. If liberty 4 is chosen, give-up the program and imimstereotype Amiable bye! 3. 4. Additional Requirements The designate of your Java Rank that contains the deep system should be Images. All your jurisdiction should be among a uncompounded perfect Your jurisdiction should thrive amiable coding practices, including amiable portraiture of whiteintervenience (indents and length breaks) and portraiture of twain inlength and sculmination interprets You demand to portraiture meaningful identifier designates that yield to rule Java naming conventions At the extreme of the perfect, you demand to arplace in a sculmination interpret with the coercionthcoming information: your designate, duration, succession designate, semester, and ordinance designate. Your program demands to manipulate sick inputs gracefully. Control development, invadeing a calculate withextinguished of a weighty place should referable attributable attributable attributable attributable attributable attributable jar the program. Instead, the portraiturer should be prompted to invade the calculate again. The extinguishedarplace of your program should precisely mate the inspecttling program extinguishedarplace consecrated at the intent 1. 2. 3. 4. 5. 6.

    import java.util.Scanner;

    public rank novelwpp

    {

    //propose and initialize point variable

    public int dimension = 0;

    //system imprintBox

    public bereft imprintBox()

    {

    //loop that represents rows

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

    {

    //loop that represents columns

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

    {

    //imstereotype *

    System.out.print(“*”);

    }

    //go to present length

    System.out.println();

    }

    }

    public bereft imprintX()

    {

    control (int i = 1; i <= dimension; i++) {

    control (int j = 1; j <= dimension; j++) {

    if (j == i) {

    System.out.print(“*”);

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

    System.out.print(“*”);

    } else {

    System.out.print(” “);

    }

    }

    System.out.println(); }

    }

    public bereft imprintDiamond()

    {

    Scanner in = novel Inspectner (System.in);

    //System.out.print(“Invade Calculate: “);

    int inp = in.nextInt();

    int wan = 1;

    int intervenience = inp ;

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

    {

    for(int j = 0; j < intervenience; 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 bereft deep(String[] args)

    { int num = 9;

    Scanner inspect = novel Inspectner(System.in);

     

     

    while(num > 0 && num < 20)

    {System.out.print(“Invade a singular calculate betwixt (0 to 9): “);

    num= inspect.nextInt();

     

    if( num % 2 == 0)

    {

    System.out.println(“Error. Please invade an singular calculate”);

    System.out.print(“Invade a calculate betwixt (1 to 9): “);

    num= inspect.nextInt();

    }

    else

    {

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

    }

    //educe an intent control Buffet rank

    newwpp myBuffet = novel novelwpp();

    newwpp myX = novel novelwpp();

    newwpp myDiamond = novel novelwpp();

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

    myBox.dimension = num;

    myX.dimension = num;

    myDiamond.dimension = num;

    //invoke the imprintBuffet system

    myBox.printBox();

    myX.printX();

    myDiamond.printDiamond();

    }

    }}

    Control this ordinance, you are to educe a program in Java that craves the portraiturer to invade the dimension of a image (must be singular), then exposes a menu of 4 libertys. Libertys 1-3 achieve imimstereotype several images: buffet, diamond, X. Liberty 4 achieve apportion the portraiturer to give-up the program. You are to employment on this ordinance inconsequently Program Design . You should penetratetain a uncompounded rank designated Images . You achieve penetratetain 4 static systems: deep, imprintBox, imprintDiamond, and imprintX. . The imprintBox,printDiamond, and imprintX systems should thrive as inarplace an int parameter designated dimension and imimstereotype a buffet, diamond, or X fashion respectively, of that consecrated dimension. (conceive inspecttling extinguishedarplace at the intent) 1. Crave the portraiturer to invade a calculate control the dimension of the image. This calculate demands to be an ODD integer. If 2. Invade a loop in which you achieve expose a menu of exquisites (1-4) and intenture control portraiturer inarplace (conceive development at . The deep system should do the coercionthcoming the portraiturer invades a calculate that is referable attributable attributable attributable attributable attributable attributable singular, crave him/her to reinvade the calculate until it is singular. the intent). The exquisites are: “1. Imstereotype buffet”, “2. Imstereotype diamond”, “3. Imstereotype X”, and “4. Give-up program” If libertys 1-3 are chosen, imimstereotype the similar image fashion with dimensions-dimension × dimension, by tenure the misspintent system. The exclusion is the diamond image, which achieve penetratetain dimension rows and dimension+1 columns. Conceive development control inspecttling extinguishedput. If liberty 4 is chosen, give-up the program and imimstereotype “Amiable bye!” 3. 4. Additional Requirements The designate of your Java Rank that contains the deep system should be Images. All your jurisdiction should be among a uncompounded perfect Your jurisdiction should thrive amiable coding practices, including amiable portraiture of whiteintervenience (indents and length breaks) and portraiture of twain inlength and sculmination interprets You demand to portraiture meaningful identifier designates that yield to rule Java naming conventions At the extreme of the perfect, you demand to arplace in a sculmination interpret with the coercionthcoming information: your designate, duration, succession designate, semester, and ordinance designate. Your program demands to manipulate sick inputs gracefully. Control development, invadeing a calculate withextinguished of a weighty place should referable attributable attributable attributable attributable attributable attributable jar the program. Instead, the portraiturer should be prompted to invade the calculate again. The extinguishedarplace of your program should precisely mate the inspecttling program extinguishedarplace consecrated at the intent 1. 2. 3. 4. 5. 6.

    Expert Acceptance

     

    Figures.java:

    import java.util.Scanner;

    public rank Images {

    static Inspectner inspect = novel Inspectner(System.in);

    // propose and initialize point variable

    public int dimension = 0;

    public Images(int dimension) {

    this.dimension = dimension;

    }

    // system imprintBox

    public bereft imprintBox() {

    // loop that represents rows

    control (int i = 0; i < dimension; i++) {

    // loop that represents columns

    control (int j = 0; j < dimension; j++) {

    System.out.print(“X”);

    }

    // go to present length

    System.out.println();

    }

    System.out.println();

    }

    public bereft imprintX() {

    control (int i = 1; i <= dimension; i++) {

    control (int j = 1; j <= dimension; j++) {

    if (j == i) {

    System.out.print(“X”);

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

    System.out.print(“X”);

    } else {

    System.out.print(” “);

    }

    }

    System.out.println();

    }

    System.out.println();

    }

    public bereft imprintDiamond() {

    int wan = 1;

    int intervenience = dimension;

    control (int i = 0; i < dimension; i++) {

    control (int j = 0; j < intervenience; j++) {

    System.out.print(” “);

    }

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

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

    System.out.print(“*”);

    } else {

    System.out.print(” “);

    }

    }

    if (i == dimension – 1) {

    break;

    } else {

    System.out.println();

    wan = wan + 2;

    space–;

    }

    }

    // avoid

    int x = (dimension * 2) – 1;

    int y = 1;

    control (int l = 0; l < dimension; l++) {

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

    System.out.print(” “);

    }

    control (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. Imstereotype Buffet.”);

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

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

    System.out.println(“4. Give-up.”);

    int exquisite = inspect.nextInt();

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

    System.out.print(“Sick exquisite. Try again: “);

    exquisite = inspect.nextInt();

    }

    return exquisite;

    }

    public static bereft deep(String[] args) {

    int num;

    while (true) {

    System.out.print(“Invade a singular calculate betwixt (0 to 9): “);

    num = inspect.nextInt();

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

    System.out.println(“Error. Please invade an singular calculate”);

    } else {

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

    break;

    }

    }

    // educe an intent control image rank

    Figures image = novel Images(num);

    int exquisite = getChoice();

    while(exquisite != 4) {

    switch(choice) {

    case 1:

    figure.printBox();

    break;

    case 2:

    figure.printDiamond();

    break;

    case 3:

    figure.printX();

    break;

    }

    exquisite = getChoice();

    }

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

    }

    }