Java Finding Tree Height Using Simple Geometry and Java Coding

AI Thread Summary
The discussion focuses on calculating the height of a tree using simple geometry, specifically the relationship between the angle of elevation and the length of the shadow. The formula used is tan(angleElevation) = treeHeight / shadowLength. A Java code snippet is provided to implement this calculation, but an error arises due to the incorrect usage of the tangent function. The solution involves using Math.tan to correctly reference the tangent function from the Math package, which resolves the error and allows the program to compute the tree height successfully.
obeying
Messages
8
Reaction score
0
Simple geometry can compute the height of an object from the object's shadow length and shadow angle using the formula: tan(angleElevation) = treeHeight / shadowLength. Given the shadow length and angle of elevation, compute the tree height.

What I have so far:

import java.util.Scanner;
import java.lang.Math;

public class TreeHeight {
public static void main(String [] args) {
double treeHeight = 0.0;
double shadowLength = 0.0;
double angleElevation = 0.0;

angleElevation = 0.11693706; // 0.11693706 radians = 6.7 degrees
shadowLength = 17.5;

treeHeight = shadowLength * tan(angleElevation);

System.out.print("Tree height: ");
System.out.println(treeHeight);

return;
}
}
Error that I'm getting:

TreeHeight.java:14: cannot find symbol
symbol : method tan(double)
location: class TreeHeight
treeHeight = shadowLength * tan(angleElevation);

1 error
 
Technology news on Phys.org
obeying said:
Simple geometry can compute the height of an object from the object's shadow length and shadow angle using the formula: tan(angleElevation) = treeHeight / shadowLength. Given the shadow length and angle of elevation, compute the tree height.

What I have so far:

import java.util.Scanner;
import java.lang.Math;

public class TreeHeight {
public static void main(String [] args) {
double treeHeight = 0.0;
double shadowLength = 0.0;
double angleElevation = 0.0;

angleElevation = 0.11693706; // 0.11693706 radians = 6.7 degrees
shadowLength = 17.5;

treeHeight = shadowLength * tan(angleElevation);

System.out.print("Tree height: ");
System.out.println(treeHeight);

return;
}
}
Error that I'm getting:

TreeHeight.java:14: cannot find symbol
symbol : method tan(double)
location: class TreeHeight
treeHeight = shadowLength * tan(angleElevation);

1 error

Hey obeying! Welcome to MHB! ;)

I believe that should be [M]Math.tan[/M].
That is, the tangent function is part of the Math package and that needs to be specified.
 
I like Serena said:
Hey obeying! Welcome to MHB! ;)

I believe that should be [M]Math.tan[/M].
That is, the tangent function is part of the Math package and that needs to be specified.

Awesome! Thank you it worked!
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top