Created
October 15, 2010 19:05
-
-
Save raphaelsaunier/628744 to your computer and use it in GitHub Desktop.
TrigLength
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.text.DecimalFormat; | |
public class TrigLength | |
{ | |
public static void main (String[] args) { | |
Scanner scan = new Scanner(System.in); | |
int distance_trigpoints, angle_from_trigpoint1, angle_from_trigpoint2; | |
double distance_point1, distance_point2; | |
System.out.print("Enter the distance between the trig points and then click ENTER: "); | |
distance_trigpoints = scan.nextInt(); | |
System.out.print("Enter the angle in degrees from trig point 1 and then click ENTER: "); | |
angle_from_trigpoint1 = scan.nextInt(); | |
System.out.print("Enter the angle in degrees from trig point 2 and then click ENTER: "); | |
angle_from_trigpoint2 = scan.nextInt(); | |
distance_point1 = (distance_trigpoints * Math.sin(angle_from_trigpoint2 * Math.PI/180)) / (Math.sin((angle_from_trigpoint1 * Math.PI/180) + (angle_from_trigpoint2 * Math.PI/180))); | |
distance_point2 = (distance_trigpoints * Math.sin(angle_from_trigpoint1 * Math.PI/180)) / (Math.sin((angle_from_trigpoint1 * Math.PI/180) + (angle_from_trigpoint2 * Math.PI/180))); | |
System.out.println("The distance from point 1 is " + (new DecimalFormat("0.00")).format(distance_point1) + ": "); | |
System.out.println("The distance from point 2 is " + (new DecimalFormat("0.00")).format(distance_point2) + ": "); | |
if (distance_trigpoints < 0) // <- No semicolumn here! | |
System.out.println("You have entered a negative distance. Please enter a positive integer"); | |
if (angle_from_trigpoint1 < 0) | |
System.out.println("Negative angle not possible. Please enter a positive integer"); | |
if (angle_from_trigpoint2 < 0) | |
System.out.println("Negative angle not possible. Please enter a positive integer"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment