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!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top