Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Evaluate the integrals in Problem ON

Answered: 1 week ago