Can anybody help mi getting the area so that I display it on a message?

Here is the driver:

import javax.swing.JOptionPane;



public class Driver {



public static  void main(String[] args) {
Rectangle tennisCourt = new Rectangle();


{


JOptionPane.showInputDialog(null," Enter Lenght: " + tennisCourt.setLength() );


JOptionPane.showInputDialog(null," Enter Lenght: " + tennisCourt.setWidth() );
JOptionPane.showMessageDialog(null, "The area of a rectangle with            a  length of" +  tennisCourt.getLength()+ "and    a width of" + tennisCourt.getWidth()
+ "is" + tennisCourt.getArea());


}
}
}


Here is the class!


public class Rectangle
{
private double width;
private double length;
private double area;
public Rectangle() {}


public Rectangle     (double newWidth, double newLength, double newArea )
{
width = newWidth;
length = newLength;
area = newArea;
}


public double getLength()
{
return length;
}
public double getWidth()
{
return width;
}



public double setLength() {
// TODO Auto-generated method stub
return length;
}
public double setWidth() {
// TODO Auto-generated method stub
return width ;
}


public double getArea() {
area =  length * width;
return area;
}
public double setArea() {


return area;
}
public String toString()
{
return ("Length: " + length + "; Width: " + width + "; Area: " +        area );


}
}

Edited 3 Years Ago by Nick Evan: Fixed formatting

you've got your setters messed up. you are not setting the actual values, you are just getting them.
replace your setters to

public void setLength(double length){
this.length = length;
}
This article has been dead for over six months. Start a new discussion instead.