ICM Week 8: Midterm! My fortune telling, Magic 8 Ball calculator

Fortune Calculator

Last week we discussed ideas for our midterm and I presented something I’d been thinking about since Week 4. My idea was to create a calculator that doesn’t work…or works more like a Magic 8 Ball than a calculator. It actually does add and subtract but what you get are strings, not numbers.

When I started working on it, I was going crazy trying to figure out how to create a class for every property that a button would have – rollover detection, button press detection, the value of each button, and how to store the value of each button so that you could actually do a calculation. Then, it was suggested that I use a library to create the buttons. (Duh.) I chose ControlP5. Admittedly, using the library was a revelation and it helped me progress my work forward by at least a week. I think I would have lost it if I had to create an entire button class in a week, and figure out how to make the rest of the calculator work.

So after all that, I again got help adding the buttons and creating the first of 2 switch statements to determine button press. The second, I made on my own. But, eventually I was able to do a lot of work alone, creating the array of strings, calling the functions to print the strings, creating outlines for the buttons, and adding the ability to subtract. I also added buttons to the calculator that have nothing to do with math at all. Like a ‘Q’ button, an ‘&’ button, and a ‘?’ button. I may create put in other mathematical operators, ‘*’ and ‘/’ so that it seems more like a true calculator…we’ll see.

I am disappointed that the ControlP5 library doesn’t have much in the way of customization of the buttons. The text is really tiny and I’d prefer to make it look more calculator-like. Eventually, maybe I will end up creating a button class and then be able to modify the look a little bit better. For now, I’m happy that I have a calculator that (mostly) works.

If you use it, remember that it can only add or subtract two numbers. If you do a compound calculation, like ‘N + Y – R & S’, you’ll get results from the last operator used, in this example ‘&’. It also works best if you ‘Clear’ your results after each calculation.

Fortune telling, Magic 8 Ball Calculator

Leave a Reply

Your email address will not be published. Required fields are marked *