Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# Using the Math Class + generic question

Rykurex Peters
Greenhorn
Posts: 21
Hey all, I'll just get straight to it, when I input a vertical height of 4 and a top angle of 30 (in degrees) I get ridiculous answers,
for example, the ladder length should be 5, and the floor length should be 3 (a 3, 4, 5 triangle) but I get huge decimal answers and can't figure out why.

Here is the code of the class containing the main method and scanner

And this is the code of the calculations etc

My other, generic, question is about the constructor and the print statements at the end of the User class. Do I have to assign values to things such as bottomAngle, floorLength etc in the constructor, and then use +bottomAngle in the println statements?
Or is there a way I can use getBottomAngle() and call the "local variable" (is that the right term)??

Thanks for all your help so far guys.
The reason I'm not sure what the problem is, is because it is clearly not giving me the answer as if I had done cosine, sine, or tangent of the input angle in radians, I have checked on my calculator and I've no idea where these values are coming from!!

Paul Clapham
Sheriff
Posts: 21443
33
Everything there looks okay to me except for your assertion that a 3-4-5 right triangle has a 30-degree angle, and that shouldn't make a huge difference. (I haven't seriously checked your trig calculations either but they look like they're going in the right direction anyway.)

So can you post more detail about the answers you're getting? I'm sure you aren't going to get 5 for ladder length, but you should get something around there.

Rykurex Peters
Greenhorn
Posts: 21
This is why I shouldn't do these things at such ridiculous times.
You're correct, and I'm taking a maths degree thinking a 3 4 5 triangle has a 30 degree angle :|

I'm just going to say ohhh it happens to the best of us and quietly brush this one away ;)
Thanks though

Campbell Ritchie
Sheriff
Posts: 50695
83
Agree. If you are taking maths you should never think there is a 30° angle. You should have said π÷6