Here is the code from both classes, the user has to input the value for two angles and a length for part of a triangle. I understand Java uses radians, but even with a simple conversion either using Math.toDegrees or * 180/Math.Pi
it still gets the wrong answer. For example when the angle 30 is entered, 100 * tan(30)
degrees should give 57.1, however I get 44.92.... The Code:
/**Class to implement math methods, and math import
*
*/
/**
* @author Oli
*
*/
public class Balloon {
//Attributes
private int angle1;
private int angle2;
private double distance1;
private int time;
private double h2;
//Consttructor
public Balloon (int ang1, int ang2, double dist1, int t1){
angle1 = ang1; angle2 = ang2; distance1 = dist1; time = t1;
}
//Methods to calculate angles, distances and time
public double height1(){
double h1;
h1 = distance1 * (Math.tan(angle1*180/Math.PI));
return h1;
}
public double height2(){
double h2;
h2 = distance1 * (Math.tan(angle2))-(Math.tan(angle1));
return h2;
}
public double speed(){
double sp1;
sp1 = h2/time;
return sp1;
}
public double BalloonDistance(){
double BD1;
BD1 = distance1 / (Math.cos(angle2));
return BD1;
}
}