File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Using the Math Class + generic question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using the Math Class + generic question" Watch "Using the Math Class + generic question" New topic

Using the Math Class + generic question

Rykurex Peters

Joined: Oct 28, 2012
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

Joined: Oct 14, 2005
Posts: 19973

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

Joined: Oct 28, 2012
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

Joined: Oct 13, 2005
Posts: 46412
Agree. If you are taking maths you should never think there is a 30° angle. You should have said π÷6
I agree. Here's the link:
subject: Using the Math Class + generic question
It's not a secret anymore!