So I have an assignment which works with a Stack and Infix to Postfix calculations. Now I have the infix to Postfix calculation but.. There is this part that it says that I have to make up a calculation of 4 random numbers and random operators.
So I have an array of numbers 1-9, and a char array consisting of +, - and *.
I can make my random calculation and put it in a string object, but I can not seem to store the calculation in an Integer variable in a proper way. With the proper priorities of operators.. I have tried some Switch and If-else statements but I can't find a way out anymore.
I have a Stack and an InToPost class which were given.
The calculation looks like this in code:
String calculation = Integer.toString(numbers[random.nextInt(9)])
+ Character.toString(operators[random.nextInt(2)])
+ Integer.toString(numbers[random.nextInt(9)])
+ Character.toString(operators[random.nextInt(2)])
+ Integer.toString(numbers[random.nextInt(9)])
+ Character.toString(operators[random.nextInt(2)])
+ Integer.toString(numbers[random.nextInt(9)]);
What I want now is to calculate it, but it's hard with the priority of * operator.
All help will be appreciated :)