473,496 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

I have a doubt as to how to calculate trigo functions in java.

Krithiga Ravi
6 New Member
Hi, below is the simple calculator that I was making, but then I got stuck as I don't know how to implement a switch statement instead of the if-else-if statement for the calculation of the operations.


class CalculatorOperations
{
public static void main (Strings [ ] args)
{
System.out.println (“Calculation Section with operations:”);
System.out.println (“Enter the two integers”);
int value1;
int value2;
void get data (int a; int b)
{
value1 = a;
value2 = b;
}

System.out.println (“Enter operation ( + - * / ) : ”);
char operator;
void get data (char o)
{
char operator = o;
}
int calculate result ( );
{
int result;

if (operator = “ + ”)
{
result = value1 + value2;
}

else if (operator = “ - ”)
{
result = value1 - value2;
}

else if (operator = “ * ”)
{
result = value1 * value2;
}

else if (operator = “ / ” && value2 != 0)
{
result = value1 / value2;
}

else
{
System.out.println (“unknown operator” + operator + “Please try again.”);
}
System.out.println (“ The result is: ” +result);
}


System.out.println (“Trigonometry Section: ”);

System.out.println (“S: SIN ”);
System.out.println (“C: COS”);
System.out.println (“T: TAN”);

System.out.println (“Enter a number”);
int num1;
void get data (int n)
{
num1 = n;
}

I don't know why but the Calculation Section with Operations isn't just working. I tried all ways to modify the code, but I don't know where I went wrong. Could you please advice me.

Also, I am confused in the part where I need to insert TRIGONOMETRIC FUNCTIONS, because my very first doubt is whether the angle to be entered is degree or rad? Also, how do I calculate sin, cos, and tan? Is it same s=way as I did for the Operations?
Dec 27 '10 #1
7 1508
Amit Kumar M
9 New Member
Have you run this code at least once? There are lot of compilation error in your program e.g.
Expand|Select|Wrap|Line Numbers
  1. public static void main (Strings [ ] args) 
There is no inbuilt
Expand|Select|Wrap|Line Numbers
  1. Strings
class in Java.

Please provide working code while looking for answers. Use [code] tags.

Thanks,
Amit
Dec 27 '10 #2
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Please see this link for more information about switch statement.

Regards
Dheeraj Joshi
Dec 27 '10 #3
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
By the way, You can not do switch on String data type. You must use Enum type to use switch statement.

In your case define operators as Enums and use them for switch.

Regards
Dheeraj Joshi
Dec 27 '10 #4
Krithiga Ravi
6 New Member
Oh thanks for the answer Joshi and Amit. But then my problem is that I just started learning Java 2 months ago. But then, I still haven't learnt about Enum

And I am still not yet sure as to how to get the sin, cos and tan in a java calculator. As for the code, its just a beginner code for me.
Dec 27 '10 #5
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Please follow this link for Enums.

Regards
Dheeraj Joshi
Dec 28 '10 #6
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Check this link for Math class in Java.

Regards
Dheeraj Joshi
Dec 28 '10 #7
Krithiga Ravi
6 New Member
Oh thanks a lot for the links. They were really helpful.
Dec 28 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
14579
by: ProgDario | last post by:
Hello, in the site I found a lot of complicated examples, but I can't find the simple one I'm looking for. The problem is: I have 1 jython file (script1.py) with a function named...
3
1761
by: praba kar | last post by:
Dear All, I am new to Python. I am in need of some sorting functions (eg) numerical sorting functions and alphapetical sorting functions. I have searched through net But I cannot find any...
10
4235
by: Alex Gerdemann | last post by:
Hello, I have spent a bunch of time converting a Java program I wrote to C++ in order to improve performance, and have found that it is not necessarily faster. Specifically, I'm writing a...
1
1530
by: Mohamed Fysal | last post by:
Hi , I have written a Regular DLL and derived the App class from CNDKClient class so that this DLL is used by another EXE to act as a Client to a Server Application which I developed deriving...
2
1319
by: Gonzosez | last post by:
I have created several functions and subs in both VB and Java. How can I put these into a file to be called by different pages. Thanks in advance, Gonzo
458
20764
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
5
19363
by: Ramkrish | last post by:
i have already used Simple Date Format method.i got the time from the system.that i am stored in sql.in sql i used datetime datatype.it gives date and time.but i need only time.and how to subtract...
15
479
by: niklaus | last post by:
Hi, I have a doubt regarding inline functions. 1) When does the inline of function happen. During the preprocessing stage or just before the object code is produced. Can we see the source code...
8
1902
by: Gabriele | last post by:
I'm studying differences between those two architecture in order to choose a setup to develop a completely new application. I'm a programmer with some experience on C++ and PHP and i have basic...
3
2019
by: sukatoa | last post by:
Good day Is it safe to use java regex to extract links and email addresses of a specific webpage?(this is not intended for malicious activity) We are on the final stage in college, and we have...
0
7160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6878
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.