I know there have been Java questions about triangles on here already, but I've tried looking and can't find a solution to my problem.
I'm working on a homework assignment where I need to provide the lengths of the sides of the triangle (which the user can provide in any order.
I have to find the type of the triangle (right, isosceles, etc) except for scalene since that wasn't in the instructions. I also have to find the area of the triangle.
I have over a hundred lines but the still doesn't work at all. There aren't any errors that prevent it from compiling; it just doesn't work properly when executed.
Any help would be much appreciated.
import javax.swing.JOptionPane;
public class TriangleChecker {
public static void main(String[] args) {
Boolean triangle, right, equilateral, isosceles;
triangle = false;
right = false;
equilateral = false;
String side1, side2, side3;
double s1, s2, s3, perimeter, areai, bi, hi, fhi, be, he, fhe, areae, br, hr, arear;
System.out.println("Hello welcome to the Triangle Checker");
side1 = JOptionPane.showInputDialog("Please enter side 1 of the triangle.");
side2 = JOptionPane.showInputDialog("Please enter side 2 of the triangle.");
side3 = JOptionPane.showInputDialog("Please enter side 3 of the triangle.");
s1 = Double.parseDouble(side1);
s2 = Double.parseDouble(side2);
s3 = Double.parseDouble(side3);
if ((s1 > s2 + s3) || (s2 > s1 + s3) || (s3 > s1 + s2)) {
triangle = false;
}
else {
triangle = true;
}
if ((s1 > s2 && s1 > s3) && (s1*s1 == s2*s2 + s3*s3)) {
right = true;
}
else if((s2 > s1 && s2 > s3) && (s2*s2 == s1*s1 + s3*s3)) {
right = true;
}
else if((s3 > s1 && s3 > s2) && (s3*s3 == s1*s1 + s2*s2)) {
right = true;
}
else {
right = false;
}
if((s1 == s2) && (s1 == s3)) {
equilateral = true;
right = false;
isosceles = false;
}
else {
equilateral = false;
}
if((s1 == s2) && (s1 != s3)) {
isosceles = true;
}
else if((s1 == s3) && (s1 != s2)) {
isosceles = true;
}
else if((s2 == s3) && (s1 != s3)) {
isosceles = true;
}
else {
isosceles = false;
}
if((isosceles = true) && (s1 == s2)) {
bi = (s3/2);
hi = ((s1*s1) - (bi*bi));
fhi = Math.sqrt(hi);
areai = bi * fhi;
}
else if((isosceles = true) && (s1 == s3)) {
bi = (s2/2);
hi =((s1*s1) - (bi*bi));
fhi = Math.sqrt(hi);
areai = bi * fhi;
}
else if((isosceles = true) && (s2 == s3)) {
bi = (s1/2);
hi = ((s2*s2) - (bi*bi));
fhi = Math.sqrt(hi);
areai = bi * fhi;
}
else {
bi = 0;
hi = 0;
fhi = 0;
areai = bi * fhi;
}
if(equilateral == true) {
be = (s1/2);
he = ((s2*s2) - (be*be));
fhe = Math.sqrt(he);
areae = be*he;
}
else {
be = 0;
he = 0;
fhe = 0;
areae = 0;
}
if((right = true) && (s1 < s2) && (s1 < s3) && (s2 < s3)) {
br = (s1/2);
hr =(s2);
arear = br*hr;
}
else if((right = true) &&(s1 < s2) && (s1 < s3) && (s3 < s2)) {
br = s1/1;
hr = s3;
arear = br*hr;
}
else if((right = true) && (s2 < s1) && (s2 < s3) && (s1 < s3)) {
br = s2/2;
hr = s1;
arear = br*hr;
}
else if((right = true) && (s2 < s1) && (s2 < s3) && (s3 < s1)) {
br = s2/2;
hr = s3;
arear = br*hr;
}
else if((right = true) && (s3 < s1) && (s3 < s2) && (s1 < s2)) {
br = s3/2;
hr = s1;
arear = br*hr;
}
else if((right = true) && (s3 < s1) && (s3 < s2) && (s2 < s1)) {
br = s3/2;
hr = s2;
arear = br*hr;
}
else {
br = 0;
hr = 0;
arear = 0;
}
perimeter = s1 + s2 + s3;
if(triangle = true) {
System.out.println("This is a triangle.");
}
else {
System.out.println("This does not equal a triangle.");
System.exit(0);
}
if (right == true) {
equilateral = false;
isosceles = false;
}
else if (equilateral == true) {
right = false;
isosceles = false;
}
else {
equilateral = false;
right = false;
}
if(right = true) {
System.out.println("This is a right triangle.");
}
else {
System.out.println("This is not a right triangle.");
}
if (equilateral = true) {
System.out.println("This is an equilateral triangle.");
}
else {
System.out.println("This is not an equilateral triangle.");
}
if (isosceles = true) {
System.out.println("This is an isosceles triangle.");
}
else {
System.out.println("This is not an isosceles triangle.");
}
if ((arear == 0) && (areae == 0)) {
System.out.println("The area of the triangle is " + areai + ".");
}
else if ((areai == 0) && (arear == 0)) {
System.out.println("The area of the triangle is " + areae + ".");
}
else {
System.out.println("The area of the triangle is " + arear + ".");
}
}
}