I am new to object and classes. I am creating this test program to get the area of the triangle. I kept getting 0 as the area. I have no idea where did I get it wrong.
public class Project1 {
public static void main(String args[]) {
Triangle triangle1 = new Triangle();
System.out.println("The area of the triangle with base "
+ triangle1.base + "and with width "
+ triangle1.width + " is " + triangle1.getArea());
}
}
class Triangle {
double base = 1.0;
double width = 1.0;
double getArea() {
return 1 / 2 * base * width;
}
}