Question

In: Computer Science

rite a program that will calculate the perimeter and area of a rectangle. Prompt the user...

rite a program that will calculate the perimeter and area of a rectangle. Prompt the user to input the length and width. Calculate the area as length * width. Calculate the perimeter as 2* length + 2* width. Display the area and perimeter.

Please use a proper heading in a comment block (name, date, description of the program). Please use comments in your code.

Run your program twice using different input. Copy the output and place it at the bottom of the .java class file as comments OR copy the output to a Word document and submit with the class.

Solutions

Expert Solution

RectangleAreaTest.java

import java.text.DecimalFormat;
import java.util.Scanner;


public class RectangleAreaTest {

  
   public static void main(String[] args) {
       Scanner scan= new Scanner(System.in);
       DecimalFormat df = new DecimalFormat("0.00");
       System.out.println("Enter the length: ");
       double length = scan.nextDouble();//reading length of rectangle
       System.out.println("Enter the width: ");
       double width = scan.nextDouble();//reading width of rectangle
       double area = length * width; //calculating area
       double perimeter = 2 * (length + width);//calculating perimter
       System.out.println("Area is "+df.format(area));//displaying area
       System.out.println("Perimeter is "+df.format(perimeter));//displaying perimeter
      
   }

}

Output:

Enter the length:
2
Enter the width:
5
Area is 10.0

Enter the length:
1.1
Enter the width:
2.2
Area is 2.42
Perimeter is 6.60


Perimeter is 14.0


Related Solutions

Write a Python program which uses a function to calculate the perimeter of a rectangle. a...
Write a Python program which uses a function to calculate the perimeter of a rectangle. a function named volume to calculate the volume of a cylinder volume = 3.14 x radius x radius x height .b function named volume to calculate the volume of a cuboid volume = Length x width x ht Write a Python Program to calculate the sum of all odd numbers for 2 to 20 using a for loop. 4. Write statements that assign random integers...
13. Minimizing Perimeter: What is the smallest perimeter possible for a rectangle whose area is 36...
13. Minimizing Perimeter: What is the smallest perimeter possible for a rectangle whose area is 36 in2, and what are its dimensions? Also, provide the perimeter and area equations. SHOW WORK. Perimeter Equation: _________________Area Equation: ___________________ Dimensions (include units): ___________Perimeter (include units):___________ 14. Find the linearization L(x) at x = 2 of the function, f(x)=√(x^2+12). SHOW WORK. Linearization L(x): ______________________
What are the dimensions of a rectangle whose perimeter is 5600 units and whose area is...
What are the dimensions of a rectangle whose perimeter is 5600 units and whose area is as large as possible?
Find the length and width of a rectangle whose perimeter is 21 meters and whose area...
Find the length and width of a rectangle whose perimeter is 21 meters and whose area is 20 square meters. Assign variables to the unknown(s)... Form a system of equations... Solve the system and state your answer in the context of the problem, show all steps clearly, be sure to check your answers:
The rectangle below is made up of 12 squares of the same size. Find the perimeter of the rectangle if the area of the rectangle is equal to 1728 square cm.
The rectangle below is made up of 12 squares of the same size. Find the perimeter of the rectangle if the area of the rectangle is equal to 1728 square cm.
Write a program to calculate the area of four shapes (Rectangle, triangle, circle and square). The...
Write a program to calculate the area of four shapes (Rectangle, triangle, circle and square). The program to present the user with a menu where one of the shapes can be selected. Based on the selection made, the user enters the proper input, the program validates the input (i.e all entries must be greater than zero). Once the input is entered and validated, the intended area is calculated and the entered information along with the area are displayed. Area of...
write a java program for area and perimeter of right triangle
write a java program for area and perimeter of right triangle
If the area of a square is 25 square feet, calculate the perimeter of the
If the area of a square is 25 square feet, calculate the perimeter of the square. Enter the value for the perimeter in the first blank and enter the units in the second. Enter units as ft. or square ft. Round your final answer to tenths if rounding is necessary ? 
a function named area to calculate the area of a rectangle area = Length x width...
a function named area to calculate the area of a rectangle area = Length x width 2.a function named volume to calculate the volume of a sphere volume = 4/3 x 3.14 x radius x radius x radius 3.a function named volume to calculate the volume of a cuboid volume = Length x width x ht 4. Use a loop structure to calculate the sum of all odd numbers from 1 to 17 5) Use a loop structure to calculate...
REQUIREMENTS OF THE JAVA PROGRAM: Your task is to calculate geometric area for 3 shapes(square, rectangle...
REQUIREMENTS OF THE JAVA PROGRAM: Your task is to calculate geometric area for 3 shapes(square, rectangle and circle). 1. You need to build a menu that allows users to enter options. Possible options are 'S' for square, 'R' for rectangle and 'C' for circle. HINT: you can use switch statement to switch on string input a. Invalid input should throw a message for the user. Example: Invalid input, please try again 2. Each options should ask users for relevant data....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT