Spring Semester 2002

In Lab Assignment Two: A Simple Converter
You are to write a program that calculates the trigonometric functions sine and cosine of any angle expressed in sexagesimal degrees. There are 90 sexagesimal degrees in a right angle, and 360 sexagesimal degrees in a full circle. You are being assisted by a mathematician, for which you write this program, which knows these things, and many more.

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.
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.
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.
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.
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.
The sine of that is: -1.0
The cosine of that is: 6.123233995736766E-17
frilled.cs.indiana.edu%```

So you need to do thre things for this lab:
1. Read the lab notes again, and let us know if you have questions about any or all.

2. Write a program as described above, and have it ready next week.

3. Review the first set of warmups and their solutions and expect questions from them.

Our next lab (Lab Three) will focus more on the

• first set of problems and
• their solutions.

Be prepared to look through all of them, for the next lab assignment, to be assigned next week.

Last updated: Jan 14, 2002 by Adrian German for A201