![]() |
![]() Second Summer 2002 |
You've read Chapter 2 (page 72) and looked up Appendix A2 (page 713) so
you decide to use the Math
class in the java.lang
page. You therefore check the
java.lang.Math
class in the Java API and
determine that there are two functions that implement what you need:
but as the document
says, they work on radians. Fortunately the
mathematician gives you
a formula for converting sexagesimal degrees
(d ) into radians (r ), as follows:
That makes you quickly want to look up the value of
Math.PI
but once you find it, and other than that everything seems to be taken care of with this formula. You are supposed to use this information to write a program that reads angles, expressed in integer values of sexagesimal degrees, converts them in radians, and calculates the sine and cosine of the original angles and reports them. Here's an example of how the program could behave. Everything that the computer prints is in color.
frilled.cs.indiana.edu%java Two Hello, and welcome to the conversion program. Please enter the number of degrees: 0 I will transform 0 degrees in radians. Answer is: 0.0 radians. The sine of that is: 0.0 The cosine of that is: 1.0 frilled.cs.indiana.edu%java Two Hello, and welcome to the conversion program. Please enter the number of degrees: 90 I will transform 90 degrees in radians. Answer is: 1.5707963267948966 radians. The sine of that is: 1.0 The cosine of that is: 6.123233995736766E-17 frilled.cs.indiana.edu%java Two Hello, and welcome to the conversion program. Please enter the number of degrees: 60 I will transform 60 degrees in radians. Answer is: 1.0471975511965976 radians. The sine of that is: 0.8660254037844386 The cosine of that is: 0.5000000000000001 frilled.cs.indiana.edu%java Two Hello, and welcome to the conversion program. Please enter the number of degrees: 30 I will transform 30 degrees in radians. Answer is: 0.5235987755982988 radians. The sine of that is: 0.49999999999999994 The cosine of that is: 0.8660254037844387 frilled.cs.indiana.edu%java Two Hello, and welcome to the conversion program. Please enter the number of degrees: -90 I will transform -90 degrees in radians. Answer is: -1.5707963267948966 radians. The sine of that is: -1.0 The cosine of that is: 6.123233995736766E-17 frilled.cs.indiana.edu%
Please note:
toRadians()
method in class Math
.
![]() |
And in case you are reading this offline, here's your friend the
Mathematician. He likes Fraction s, and is pouring in
some tea (he doesn't know Java, that's why he had to ask for your
help). But he knows tea fairly well.
|