Question: Description Write a Java program to compute area and perimeter of a rectangle. The program will input length and width of the rectangle from the
Description
Write a Java program to compute area and perimeter of a rectangle. The program will input length and width of the rectangle from the user, compute area and perimeter, and display length, width, area, and perimeter.
Do this assignment using procedural programming.
Implementation
Create a static method computeArea that has two parameters double len and double wid to receive length and width values and returns area as a double.
Create a static method computePerim that has two parameters double len and double wid to receive length and width values and returns perimeter as a double.
In the main method, do the following:
Input length and width values from the user.
Call static computeArea and computePerim to calculate area and perimeter.
Display output.
Method Headers
Here are the proposed method headers for computeArea and computePerim:
public static double computeArea (double len, double wid)
public static double computePerim (double len, double wid)
Test Data
Test the program for the following length and width values:
30, 20
Test Output:
For the above test input, the output should look as below:
Length: 30
Width: 20
Perimeter: 100
Area: 600
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
