Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program which asks the user to enter the length and width of a rectangle

ID: 3815326 • Letter: W

Question

Write a program which asks the user to enter the length and width of a rectangle and computes the area The program MUST include the following methods. readLength: This method asks the user for the length of the rectangle, and returns the length. readwidth: This method asks the user for the width of the rectangle and returns the width. computeArea: This method takes the length and width as input and returns the computed area of the rectangle. display solution: This method displays the solution to the problem. You will need to think very carefully about how these methods should work together to find the solution. Input Validation: The length must be positive. The width must be positive. Requirements: All four of the required methods must be implemented, and all must be correctly used within your program to get credit.

Explanation / Answer

Answer:

java programe for area of rectangle:

import java.util.*;

import java.util.Scanner;

public class AreaOfRectangle

{

    public static vid main(String args[])

      double length;

      double width;

      double area;

      length=readLength();

      width=readWidth();

       area=computeArea(lenth,width);

      displaySolution(length,width,area);

     }

    public static double readLength()

      {

          Scanner keyboard=new Scanner(System.in);

          System.out.println("Enter length");

          double length=keyboard.nextDouble();

          System.out.println("the lengthis "+length);

          return length;

      }

      public static duble readWidth()

        {

          Scanner keyboard=new Scanner(System.in);

           double width;

           System.out.println("Enter width");

           width=keyboard.nextDouble();

            System.out.println("The width is "+width);

            return width;

         }

         public static double computeArea(double length,double width)

           {

              double area=length*width;

              Syatem.out.println("The area is: "+area);

              return area;

            }

        public static void displaySolution(double length,double width,double area)

         {

            System.out.println("The length is: "+length);

            System.out.println("The width is: "+width);

            System.out.println("The area is: "+area);

         }

}

Output:

Enter length 2

The length is 2

Enter width

The width is 3

The area is 6

The length is: 2

The width is: 3

The area is: 6

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote