Results 1 to 8 of 8
 09262010, 07:37 PM #1Member
 Join Date
 Sep 2010
 Posts
 4
 Rep Power
 0
Angle to Radians and Calculate the Cosine
I need to finish this code, to prompt an angle in radians and calculate its cosine.
Im a beginner and this is all very confusing still. Please help??? Anyone?
import javax.swing.*;
import java.text.*;
public class SimpleTrig{
public static void main(String[] args) {
// I need this code...
System.exit(0);
}
}
1 Declare a variable angle as double
2 Declare a variable angleCosine as double
3 Declare a variable inputStr with data type String
4 Write a code to allow ask a user to type in the angle, store it to inputStr. Then convert inputStr to the corresponding data type of angle, and store the result to variable angle
5 Write a code to compute cosine of the variable angle and store the result to angleCosine. Please use Math.cos(angle) method to compute the cosine of this angle.
3.6. Please use JOptionPane.showMessageDialog to display the value of angleCosine on the screen.

The instructions basically tell you exactly what you need to do here. If you don't understand them, you should first study (or restudy) your notes and texts and based on that information give it a try  you've nothing really to lose by doing this and all to gain. If you still are stuck, then please post your attempt along with any errors you're getting and any specific questions you may have. Remember that the more specific the question, usually the better the answer. For instance, questions like "I have no idea how to do this..." usually can best be answered by a link to a tutorial while questions like "I don't know how to get information from the user using JOptionPane..." usually result in more direct recommendations and code corrections.
Best of luck and welcome to the forum!
 09262010, 07:52 PM #3Member
 Join Date
 Sep 2010
 Posts
 4
 Rep Power
 0
This is my attempt.
double angle;
double angleCosine;
String inputStr;
inputStr = JOptionPane.showInputDialog(null, "Please enter the angle");
angle = Math.cos(angle);
im completely stuck after this point. None of my notes help me in this process.
 09262010, 07:59 PM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
Lousy attempt; the cosine of an angle isn't an angle, it is a number in the range [1, 1] (also see your point 5 in your requirements). The most daunting point is where you have to convert your String to a type appropriate for the Math.cos( ... ) method.
kind regards,
Jos
 09262010, 08:03 PM #5Member
 Join Date
 Sep 2010
 Posts
 4
 Rep Power
 0
How do i convert the string?
 09262010, 08:04 PM #6
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
 09262010, 08:07 PM #7Member
 Join Date
 Sep 2010
 Posts
 4
 Rep Power
 0
the same data type as the angle, so i would say double?

The Double class has a method called parseDouble that takes a String parameter and returns a double. e.g.,
Java Code:String myString = "1.2345"; double myDouble = Double.parseDouble(myString);
Similar Threads

is Cosine Similarity the Default Similarity in Lucene?
By sethu.iit@gmail.com in forum LuceneReplies: 0Last Post: 06302010, 09:49 AM 
AffineTransform begin at custom angle
By crazycat03 in forum AWT / SwingReplies: 3Last Post: 01252010, 08:00 AM 
Java3D Vector3d.angle(Vector3d)
By Duesentrieb in forum Advanced JavaReplies: 5Last Post: 01202009, 07:47 PM 
calculate fft
By ram.west in forum Advanced JavaReplies: 2Last Post: 08272008, 03:05 AM 
Calculate X and Y given starting angle and distance
By nidhirastogi in forum Java 2DReplies: 5Last Post: 08182008, 10:24 PM
Bookmarks