In the first step, I used the URList, URNode, and URLinkedList class from lab4, but I noticed some errors in my URLinkedList class, so I fixed some of the things in that class.
In the second step, I created a Stack and a Queue class. These two classes are implements from the URLinkedList class, so some of the methods within these two classes are called from the URLinkedList class, such as isEmpty and clear.
In the third step, I create a new class named InfixtoPostfix to convert the infix into postfix syntax. Postfix is also called reverse Polish. The process to achieve this goal is first to create a new object queue named q. I made the infix string into a token and stored it in this q queue. For example, 4.7 + 3.0 * 5.5 became to Q = [‘4.7’, ‘+’, ‘3.0’, ‘’, ‘5.5’]. Then, I created a new queue to store my postfix result. I also created a Stack named operator to store operators, so I can pop them and enqueue into a new queue as needed. After checking all the tokens and storing all tokens into this new queue, I returned this queue. This new queue will be Q = [‘4.7’, ‘3.0’, ‘5.5’, ‘’, ‘+’], for example.
In the fourth step, I created a new class named InfixCalculator. This class allows user input. It can evaluate the postfix queue into String result. For example, when you enter 4.7 + 3.0 * 5.5, it will come out 21.2. The process I did to evaluate the postfix is first to check what the operator is for each token object. Then, pop the last two numbers and push the result from this calculation into a new stack. After evaluating each calculation, push the final result into the stack and convert it into a string data type. For this project, I also did three extra credit tasks. The first one is “do not require blanks”. I checked the blank space within the InfixtoPostfix class, so when there is a blank occurs, just ignore it and continue for the next if statement. For the second extra credit task, which is “support negative and positive numbers”, I created another method named IntoPost2 within the InfixtoPostfix class. For this method, when there is an operator in front of a number, it belongs to the number token, otherwise, it is the actual operator that is used for calculation. And within the InfixCalculator class, I created a method named evalExp2. Nothing change in this method except the method I called from the InfixtoPostfix class is different. For the third extra credit task, which is allowing to use modulo, I added the % condition into the if statements that checked for the operation. Modulo is lower precedence than *, /, and ^, but higher than + and -.