Senior Year Shop Work

Calculator

    This assignment is a calculator. It may not seem impressive at first, but what I had to learn to get this working not many highschoolers know about. I had to learn how to do postfix notation. If you don’t know what that is, good. I’m about to explain it. We do math using a system called infix notation where the operators are in the middle of the equation. Operators being things like “plus” “minus” “multiply” “divide.” Postfix notation has the operators generally at the end. How it works is you read from left to right and when you hit an operator, you calculate the previous two numbers based on the operator you hit. The advantage of this method is that you don’t have to remember PEMDAS/GEMDAS/BODMAS/whatever your math teacher taught you. It’s baked into the equation so you can go from left to right the entire time. If you need an example, “2 + 3” becomes “2, 3, +” or “5 + 3 / 4” becomes “3, 4, /, 5, +”. If you are still confused, but interested in learning more, there are great tutorials that explain it better than I could.

    One problem there is, is that the parentheses don’t work. This is because I didn’t have the time to learn how to convert infix notation with parentheses to postfix notation. The negative button also doesn’t work, also because I didn’t have time. Dividing by 0 also results in infinity because I didn’t check if the user is dividing by 0 in the equation. This could be fixed by not letting an input of 0 after a division symbol, but this wouldn’t work if parentheses were working. The other, better, solution is to produce an error and stop the equation if you detect a division by 0.

    If I were to redo this assignment I would add support for parenthesis, exponents, and functions. I would also display when syntax is entered wrong. Currently if you enter an equation wrong, it doesn’t say anything. You just have to sit there and look through the equation to find what you did wrong.

Trivia Questions

    The first thing I had to do was come up with trivia questions. This was harder than expected, but I eventually drew inspiration from the Impossible Quiz and Hermitcraft. I decided that it would be easier to store the questions in a CSV file than to have them in multiple arrays. It cleans up the code because there are less unnecessary lines, making scrolling better. Now, if you’re inexperienced you may think more lines = better, but not necessarily. The more lines you have the more you have to scroll, and the more you have to scroll the more time you waste. Scrolling also makes finding methods/functions harder.

    One thing I learned is how to use images in JavaFX. I learned how to add fade in and fade out animations. This project taught me the true cost of thinking things will be easy. It’s never as easy as you think, then you choose a suboptimal solution. But the good thing is, after a good night’s rest you’ll be able to come up with a better solution. 

    Originally I was only going to have one variable to store how many questions were answered correctly, but I was having problems where it wouldn’t end after answering all the questions. Then, you would answer again and errors occurred. I decided to store a second variable that stores how many questions have been answered, and I used that to base when it should end.