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. You are to work on this assignment independently. Program Design You should have a single class called Shapes. You will have 5 static methods: main, printOpenSquare, printClosedSquare, printDiamond, and getShapeSize. The printOpenSquare, printClosedSquare, and printDiamond 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 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) 1. 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. 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. 5. What to Turn In You will turn in the single Shapes.java file using BlackBoard. What You Need to Know for This Assignment Conditional statements Loops Getting user input Creating and calling methods

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter3: Using Methods, Classes, And Objects
Section: Chapter Questions
Problem 13PE
icon
Related questions
Question
Use java.
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. You are to work on this assignment independently.
Program Design
You should have a single class called Shapes.
You will have 5 static methods: main, printOpenSquare, printClosedSquare,
printDiamond, and getShapeSize.
The printOpenSquare, printClosedSquare, and printDiamond 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 Xsize, 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
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.
1.
3. 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.
4.
5.
6.
What to Turn In
You will turn in the single Shapes.java file using BlackBoard.
What You Need to Know for This Assignment
Conditional statements
Loops
Getting user input
Creating and calling methods
Transcribed Image Text: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. You are to work on this assignment independently. Program Design You should have a single class called Shapes. You will have 5 static methods: main, printOpenSquare, printClosedSquare, printDiamond, and getShapeSize. The printOpenSquare, printClosedSquare, and printDiamond 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 Xsize, 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 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. 1. 3. 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. 4. 5. 6. What to Turn In You will turn in the single Shapes.java file using BlackBoard. What You Need to Know for This Assignment Conditional statements Loops Getting user input Creating and calling methods
Sample Program Output
Programming Fundamentals
NAME: [put your name here]
PROGRAMMING ASSIGNMENT 2
MENU:
1. Print closed square
2. Print open square
3. Print diamond
4. Quit program
Please select an option: 1
Enter the size of the figure (odd number): 8
Invalid figure size - must be an odd number
Renter the size of the figure: 5
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
MENU:
1. Print closed square
2. Print open square
3. Print diamond
4. Quit program
Please select an option: 2
Enter the size of the figure (odd number): 7
XXXXXXX
X
X
X
X
XXXXXXX
MENU:
1. Print closed square
2. Print open square
3. Print diamond
4. Quit program
Please select an option: 3
Enter the size of the figure (odd number): 9
XX
X X
X
X X
XX
MENU:
1. Print closed square
2. Print open square
3. Print diamond
4. Quit program
Please select an option: 4
Good bye!
Transcribed Image Text:Sample Program Output Programming Fundamentals NAME: [put your name here] PROGRAMMING ASSIGNMENT 2 MENU: 1. Print closed square 2. Print open square 3. Print diamond 4. Quit program Please select an option: 1 Enter the size of the figure (odd number): 8 Invalid figure size - must be an odd number Renter the size of the figure: 5 XXXXX XXXXX XXXXX XXXXX XXXXX MENU: 1. Print closed square 2. Print open square 3. Print diamond 4. Quit program Please select an option: 2 Enter the size of the figure (odd number): 7 XXXXXXX X X X X XXXXXXX MENU: 1. Print closed square 2. Print open square 3. Print diamond 4. Quit program Please select an option: 3 Enter the size of the figure (odd number): 9 XX X X X X X XX MENU: 1. Print closed square 2. Print open square 3. Print diamond 4. Quit program Please select an option: 4 Good bye!
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,