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

Aracted Files Aeafiectange ava (694 B) Area Rectanlge In dats at t\'mmrt is to S

ID: 3737498 • Letter: A

Question


Aracted Files Aeafiectange ava (694 B) Area Rectanlge In dats at t'mmrt is to Stich up te attached AreaRnctangle program if you k ok at the ataded program you wil tee cals to metods femte man method which do yet etattl write ad add t se methods to your program For example getLengtho is a method that takes NO parameters, so what it should do s prompt the user running the program to enter a valse for the length of the desined rectangle (getWidthO is the same as getLength() excet rs requesing the widh o the redtangle. getArea(length widh) on the cther hand does requre parameter values passed to t and the method simply cakculates the area of the rectangle dsplayDataengh, wicth, area)requres 3 Methods getLength getwidh) getAreal length with It will deplay this data either using the console or in a JOponPane message dialog

Explanation / Answer

AreaRectangle.java

import java.util.Scanner;

public class AreaRectangle {

static Scanner scan = new Scanner(System.in);

public static void main(String[] args) {

double length, width, area;

length = getLength();

width = getWidth();

area = getArea(length, width);

displayData(length, width, area);

}

public static double getLength() {

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

return scan.nextDouble();

}

public static double getWidth() {

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

return scan.nextDouble();

}

public static double getArea(double l, double w) {

return l*w;

}

public static void displayData(double l, double w, double area) {

System.out.println("Rectangle Length: "+l+" Width: "+w+" Area: "+area);

}

}

Output:

Enter the length:
5
Enter the width:
6
Rectangle Length: 5.0 Width: 6.0 Area: 30.0

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