I have made a program where I insert the length of 2 sides of a triangle and the angle between them. The program shall use this information to tell me if the triangle is equilateral, isosceles or opposite of equilateral.
If you know length a, b & x(angle between them) you can calculate the last side using the following formula: c = sqrt(aa + bb -2*abcos(x))
I have no idea why it won't work. I have done it all correctly mathematically. I believe I am using the language Java incorrectly and therefor I can't get it to work.
I believe the fault lies with the first "if" thingy. So I tried disabling the other two just for now, to be able to try if the program can recognize if the triangle is at least equilateral to begin with, it can't however.
import javax.swing.*;
public class Upp46 {
public static void main(String[] arg){
String a, b, x;
a = JOptionPane.showInputDialog("Length of a");
b = JOptionPane.showInputDialog("Length of b");
x = JOptionPane.showInputDialog("Angle between a & b");
/* "x must be converted to radians"
before it can be applied */
double ai, bi, xi, c;
ai = Double.parseDouble(a); //Length of a
bi = Double.parseDouble(b); //Length of b
xi = Double.parseDouble(x); //Angle x in degrees
xi = xi * (Math.PI/180); //Converts from degree to Radians
c = Math.sqrt(ai*ai + bi*bi -2*ai*bi*Math.cos(xi)); //Length of c
if (ai == bi && c == ai){
JOptionPane.showMessageDialog(null, "The triangle is equilateral");
}
/*else if (ai == bi && c != bi ||
ai == c && bi !=c ||
bi == c && c !=bi){
JOptionPane.showMessageDialog(null, "Triangeln är likbent");
}
else {
JOptionPane.showMessageDialog(null, "Triangeln är oliksidig");
}
*/
}
}