Progress

kevinsarav

KevinSarav

Posted on May 11, 2019

Progress

Today, I will be discussing my progress in my calculator and group project. In summary, the calculator project is almost done. The only thing missing is a display to show what's being done and fixing the calculations for multiplying/dividing and doing continuous calculations.


One major problem that occurred was when I was doing a calculation. I noticed a nullpointerexception error. That usually indicates that something wasn't instantiated properly. At first, I suspected it might have been because I was instantiating 2 ArrayLists at the same time, but then I noticed it's because I forgot to put String in between the second <>. A simple mistake like that caused me much headache searching online and trying to print stuff everywhere to find out what's wrong.

Another problem that occurred was with the calculation itself. I noticed an arrayindexoutofbounds exception. This usually indicates that I'm going beyond the limit of an array. I found out it was because of how I was doing my for loops. Logically, the operation ArrayList is going to have 1 less value than the one for my inputs. However, I didn't account for that in my code, so my code was trying to pull from beyond the operation ArrayList's size when trying to pull the last element in the input ArrayList. To solve this, I made my first for loop start at 1 (the second value in input) so that I can do the operation with that and the first value. In my method, I also subtracted 1 from the for loop value so I can start at the first operation ArrayList value. This continues until the operation ArrayList ends and not after using this method.

Another interesting problem was replicating the Windows calculator's behavior. For example, when you get a result that ends in .0, the calculator naturally displays an integer, but when the result is .0005, it displays that instead of the integer. If I wanted to use .contains() to see if the String has a decimal point, that doesn't solve the issue of differentiating between the two results I mentioned above. I realized that .contains() is too specific and I need something that can handle more unpredictable results.

That's when I realized I could use a concept I learned in a free JavaScript programming class called regular expressions (regex). With regex, I can search in a String for a pattern of characters instead of a specific sequence of characters. The magic pattern for the calculator behavior I explained above is "[.]0*\d[1-9]+". I had to use [.] because the decimal point by itself generally means any character in regex, but I want to search for a decimal point in the String. The 0* means 0 or more 0s, so if there's no zero, 1 zero or a bunch of zeroes after the decimal point, this pattern catches that. The \d[1-9]+ means any digit from 1-9 that occurs 1 or more times after the sequence (or lack thereof) of 0s falls under the pattern. This elegant solution helps me with the unpredictability of what I needed.

The group project is practically finished. The only issue is pulling data from the database into a drop-down menu. I was assigned one web page to make with HTML. It basically consisted of a text box, drop-down menus and buttons. I haven't used HTML in a long time, but the Internet proved very useful. I wasn't able to delve too much into the SQL, PHP and Apache like I originally planned, but I did learn from the code my colleagues made about them and I did make an Apache server before I knew we would be using a different technology called XAMPP. XAMPP easily installs and runs Apache and MySQL for you. I saw how the SQL codes for the project made tables for our database and the PHP codes pulled data from the tables and manipulated them.


That essentially sums up my progress. Overall, very productive day. In my next post, I hope to discuss the completion of this calculator project that I've been working on for so long. I also want to go over more specifics about the group project and hopefully my next personal project. I hope to use a different language than my preferred Java next time just to increase my exposure, hopefully using the languages we've used in this group project.

💖 💪 🙅 🚩
kevinsarav
KevinSarav

Posted on May 11, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024

How to Use KitOps with MLflow
beginners How to Use KitOps with MLflow

November 29, 2024

Modern C++ for LeetCode 🧑‍💻🚀
leetcode Modern C++ for LeetCode 🧑‍💻🚀

November 29, 2024