Write a program to create a menu driven program to do the following:
• Area of Rectangle.
• Diagonal of Rectangle.
• Perimeter of Rectangle
please answer in java pprogramming
please answer
Answers
Question:-
- To write a menu-driven program to perform the following
Area of the Rectangle
Diagonal of the Rectangle
Perimeter of the Rectangle
Answer:-
package Coder;
import java.util.*;
public class Rectangle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int ch;
System.out.println("Enter your choice\n1 for area\n2 for diagonal\n3 for perimeter");
ch = sc.nextInt();
System.out.println("Enter lenght and breadth of a rectangle");
int l = sc.nextInt();
int b = sc.nextInt();
switch (ch) {
case 1:
System.out.println("---Area of Rectangle---");
System.out.println(l * b);
break;
case 2:
System.out.println("---Diagonal of a Rectangle---");
System.out.println(Math.sqrt(Math.pow(l, 2) + Math.pow(b, 2)));
break;
case 3:
System.out.println("---Perimeter of a rectangle---");
System.out.print(2 * (l + b));
break;
default:
System.out.println("Invalid choice");
}
}
}
Variable Description:-
ch---> To accept user's choice
l--->to accept lenght of the rectangle
b--->to accept breadth of the rectangle
•Output Attached.
Answer:
Rectangle is a parallelogram with opposite sides of equal length and with all right angles (90)
Following image shows you how a Rectangle looks like
info-about-image
Following is the Java program that takes Length, Breadth as inputs and compute Area, Perimeter & Length of diagonal of a Rectangle