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?