Introduction

For this assignment, you are to create a program in Java that asks the user to enter the size of a shape (must be odd), then displays a menu of 4 options. Options 1-3 will print various shapes: closed square, open square, and diamond. Option 4 will allow the user to quit the program.

Program Design

  • You should have a single class called Shapes.
  • You will have 5 static methods: main, printOpenSquare, printClosedSquare, print Diamond, and getShapeSize.
  • The printOpenSquare, printClosedSquare, and print Diamond methods should take as input an int parameter called size and print the corresponding shape of the given size. (see sample output at the end)
  • The getShapeSize method should ask the user to enter a number for the size of the shape. This number needs to be an ODD integer. If the user enters a number that is not odd, ask the user to reenter the number until it is odd. Then, the method should return that odd number.
  • The main method should do the following:
    • Enter a loop in which you will display a menu of choices (1-4) and wait for user input (see example at the end). The choices are: "1. Print closed square", "2. Print open square", "3. Print diamond", and "4. Quit program". If option 4 is selected, quit the program and print "Good bye!". Otherwise, ask the user to enter a number for the size of the shape by calling the getShapeSize method. Then, print the corresponding shape with dimensions = size x size, by calling the appropriate method. The exception is the diamond shape, which will have size rows and size+1 columns. See example for sample output.

Additional Requirements

1. The name of your Java Class that contains the main method should be Shapes. All your code should be within a single file.

2. Your code should follow good coding practices, including good use of whitespace (indents and line breaks) and use of both inline and block comments.

3. You need to use meaningful identifier names that conform to standard Java naming conventions.

4. 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.

5. 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.

6. The output of your program should exactly match the sample program output given at the end.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.