Question
Complete a Java program which calculates area of a square or rectangle. The program continues to ask its user to choose an action among 1,
Complete a Java program which calculates area of a square or rectangle. The program continues to ask its user to choose an action among 1, 2 or 9.
If a user chooses 1 for action, the program will prompt for the width of the square and calculate the area of it.
If a user chooses 2 for action, the program will prompt for the width and height of the rectangle and calculate the area of it.
If a user chooses 9 for action, the program will terminate.
If a user inputs other integer as an action, the program will show "Invalid action."
Below is the sample screen output of the program. Those in bold and underlined are user inputs.
Choose shape (1:square, 2:rectangle, 9:exit):7
Invalid action.
Choose shape (1:square, 2:rectangle, 9:exit):1
Enter width:15
area of the square = 15 x 15 = 225
Choose shape (1:square, 2:rectangle, 9:exit):2
Enter width:26
Enter height:10
area of the rectangle = 26 x 10 = 260
Choose shape (1:square, 2:rectangle, 9:exit):9
Bye!
Write the missing statement segments (i) to (vi) ONLY of the following program
import java.util.Scanner; public class CalArea { } public static void main(String[] args) { Scanner input = (i) _; } int userAction; do { System.out.print("Choose shape (1: square, 2: rectangle, 9: exit):"); userAction = input.nextInt(); if (userAction == 1) { System.out.print("Enter width: "); int width = input.nextInt(); System.out.println("area of the square + width + " " + (width * width)); } else if (userAction: == 2) { System.out.print("Enter width:"); int width = (ii). ; System.out.print("Enter height:"); int height = input.nextInt(); System.out.println( ___ (iii) __); } else if (_ (iv) _) { System.out.println("Bye!"); } else (v)_____; System.out.println("Invalid action."); } while (_ (vi) ___); " = + width + " X
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Here is the complete Java program with the missing statement segments filled java import javautilSca...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started