Ask your own question, for FREE!
Computer Science 15 Online
OpenStudy (anonymous):

JAVA HELP can't figure out why this doesnt return the perimeter public class Triangle { private double side1; public Triangle(double side1, double side2, double side3) { if (side1 <= 0 || side2 <= 0 || side3 <= 0) { System.exit(0); } } public double getPerimeter (double side1, double side2, double side3 ) { double Perimeter = side1 + side2 + side3; return Perimeter; }

OpenStudy (anonymous):

public static void main(String[] args) { Triangle t = new Triangle(3,4,5); t.getPerimeter(3,4,5); } }

OpenStudy (espex):

I would first like to point out that you are not using a class to its potential. Your side variables, with the exception of your side1, are all local variables and are not accessible after the method closes.

OpenStudy (rsmith6559):

From what you've posted, you can't determine if a perimeter is being returned. Try changing the second line of main to: System.out.println( t.getPerimeter(3,4,5) );

OpenStudy (espex):

@rsmith6559 is correct, the perimeter IS being returned, you are just neglecting to display the results.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!