I have a problem in floats. My 1st problem is my public float area(), the problem is the result value is returning zero. 2nd is the public float computeHeight(), no value will return. I'm having headache with this. please help me thank you. Just delete if duplicate or repost. thank you
private int sideA, sideB, sideC;
private float computePerimeter;
private float area;
private float computeHeight;
public Triangle(){
}
// I want to set all sides to 10
public Triangle(int a, int b, int c){
sideA = a;
sideB = b;
sideC = c;
}
//setters & getters
//perimeter is the sum of all the sides of the triangle.
public float computePerimeter(){
computePerimeter = sideA + sideB + sideC;
return computePerimeter;
}
//A=1/2bh.
//A = Area of the triangle
//b = Length of the base of the triangle //SideB
//h = Height of the base of the triangle //SideA
public float area(){
area = 1/2 * (sideB * sideA);
return area;
}
public float computeHeight(){
sideC = 2 * (area/sideB) ;
return computeHeight;
}
public void display(){
System.out.println("Side A: "+getSideA() +" Side B: "+getSideB()+" Side C: "+getSideC() );
System.out.println("\nThe sum of all the sides of the triangle is: " +computePerimeter() );
System.out.println("The area of the triangle is: " + area() );
}
public static void main(String []args){
Triangle result = new Triangle();
result.setSideA(10);
result.setSideB(10);
result.setSideC(10);
result.display();
}