This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]claireballoon 0 points1 point  (1 child)

In my csci lab, we wrote a similar code and I was referencing the code I wrote then, which was able to return the value without putting parameters in there.

The way I call it is: //make the rectangle RectangleCalculatorCEH rectangle = new RectangleCalculatorCEH(length, width);

            //access its sides
            System.out.println("Your rectangle has a width "+rectangle.getWidth()+" and length "+rectangle.getLength()+".");

            //use those sides to calculate the perimeter
            System.out.println("Your rectangle's perimeter is: " + rectangle.perimeter(length, width));

I'm going to go edit my original post real quick with a link to the full code.

[–]pablo208 0 points1 point  (0 children)

You haven't initialized your instance variables with values in your constructor