How do you tell Java the order of operands?
Well, I am pretty new to coding and a friend of mine in a higher course got asked to make a calculator and I got interested in how would it would work.
I searched for it and the solutions I found are pretty much just a superbasic calculator, is code I could do my self (and I appreciate that cause there is a lot I do not understand yet); but I am looking for something more complex.
The proposals were something like:
Double result = 0;
System.out.println ("First opperand:");
Num1 = scan.next double();
System.out.println ("Choose operation (+,-,*,/):");
Ope = scan.next();
System.out.println ("Second opperand:");
Num2 = scan.next double();
Switch (ope) {
Case '+':
Result = num1 + num2;
break;
Case '-':
Result = num1 - num2;
break;
//and so on for each different operand that you want to add
}
System.out.println (result);
The thing is, I guess the idea of a calculator is the user to input a operation as a string and then the calculator interprets the operands and opperator. I guess you can do this somewhat easy with the string class, telling it to search the full string for successions of numbers as new opperands variables to create and anything else as a operator and check if they are valid (don't really know how to properly program that yet since I am still very new to this as I told before).
But the actual question is, how could I tell the program the order of operations of something like "20/((10+5)*2)"?
I think I could kinda deal with the basic opperators but how do I deal with parentheses?
I don't know if this is way more advanced and I won't even understand the answer or it is actually kinda simple and I just need some perspective but I am like really intriged by this and that's why I am asking