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

Write a program named AreaRectangle.java that will ask the user toenter the widt

ID: 3615088 • Letter: W

Question

Write a program named AreaRectangle.java that will ask the user toenter the width and
length of a rectangle, and then displays the rectangle’sarea. Use Dialog Boxes.

The program should call the
following methods:
• getLength – This method should ask the user toenter the rectangle’s length, and then
return that value as a double.
• getWidth – This method should ask the user toenter the rectangle’s width, and then
return that value as a double.
• getArea – This method should accept therectangle’s length and width as arguments,
and return the rectangle’s area. The area is calculated bymultiplying the length by width.
• displayData – This method should accept therectangle’s length, width, and area as
arguments, and display them in an appropriate message screen.

Explanation / Answer



//Hope this will helpyou.
import java.util.*; import javax.swing.*; import java.awt.event.*; public class AreaRectangle {

static double l,w; public static double getLength() { Scanner sc = new Scanner(System.in); System.out.print("Length:"); double l = sc.nextDouble(); return l; } public static double getWidth() { Scanner sc = new Scanner(System.in); System.out.print("Width:"); double w = sc.nextDouble(); return w; } public static double getArea(double l,double w){ return l*w; } public static void displayData(double l,double w,doublea){ String str; str = "Length:" + l +" "; str += "Width:" + w +" "; str += "Area:" + a +" "; System.out.println("Length:" + l); System.out.println("Width:" + w); System.out.println("Area:" + a); JOptionPane.showMessageDialog(null,str,"Area",1); } public static void main(String[] args) { double l,w,a; l = getLength(); w = getWidth(); a = getArea(l,w); displayData(l,w,a); }
}
//Hope this will helpyou.
import java.util.*; import javax.swing.*; import java.awt.event.*; public class AreaRectangle {

static double l,w; public static double getLength() { Scanner sc = new Scanner(System.in); System.out.print("Length:"); double l = sc.nextDouble(); return l; } public static double getWidth() { Scanner sc = new Scanner(System.in); System.out.print("Width:"); double w = sc.nextDouble(); return w; } public static double getArea(double l,double w){ return l*w; } public static void displayData(double l,double w,doublea){ String str; str = "Length:" + l +" "; str += "Width:" + w +" "; str += "Area:" + a +" "; System.out.println("Length:" + l); System.out.println("Width:" + w); System.out.println("Area:" + a); JOptionPane.showMessageDialog(null,str,"Area",1); } public static void main(String[] args) { double l,w,a; l = getLength(); w = getWidth(); a = getArea(l,w); displayData(l,w,a); }
}
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