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)

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

1 Expert Approved Answer
Step: 1 Unlock

Here is the complete Java program with the missing statement segments filled java import javautilSca... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!