question: The program should prompt the user to enter data for the width and height of the 2 rectangles and use the setWidth() and setLength() methods to store this data in the instance variables.
driver
import javax.swing.*;
public class Room
{
public static void main(String[ ] args)
{
double sq;
String input;
String input2;
double length;
double width;
input = JOptionPane.showInputDialog("Enter the length");
length = Double.parseDouble(input);
input2 = JOptionPane.showInputDialog("Enter the width");
width = Double.parseDouble(input2);
sq = Arearect.getArea();
JOptionPane.showMessageDialog(null,"The area is " + Arearect.getArea());
}
}
instantiable
public class Arearect
{
public void setWidth(double width)
{
width = width;
}
public void setLength(double length)
{
length = length;
}
public static double getArea()
{
double area;
area=length * width; //<< problem here
return area;
}
}
how to call the area and display it to driver?
or my code all mess up?