AP Computer Science --- Haas --- Rectangle
/**
* Read about variable scope, then use your vast knowledge
* to fix the program below.
*
* The following does not work! Fix it.
*/
public class Rectangle
{
int length;
int width;
String s;
/**
* constructs a rectangle with a length and width
*/
public Rectangle(int length, int width)
{
}
/**
* returns the area of a rectangle
*/
public int findArea()
{
int area = length * width;
return area;
}
/**
* returns if rectangle is "Square" or "Not Square"
*/
public String squareOrNot()
{
if (length == width)
{
String s = "Square";
}
else
{
String s = "Not Square";
}
return s;
}
}
public class RectangleTester
{
public static void main(String[] args)
{
int area=0;
Rectangle spongeBob = new Rectangle(3,4);
spongeBob.findArea();
System.out.println("spongebob area = " + area);
System.out.println("spongebob " + spongeBob.squareOrNot() + " pants.");
}
}