What Inspired You?

 I love learning new things and always wanted to build a simple app. Since I have experience in Java, I decided to learn JavaFX and build a calculator. 

What Did You Build? What does it do?:

  The program opens up a calculator built by using a GridPane to format where the user is asked to input two numbers in Textfields along with buttons used to perform the 4 basic operations: add, subtract, multiply, and divide and also pressing the clear button to clear both the input fields. Once the user enters the two numbers and presses on each button, it will produce the result. If the user enters anything other than a floating point number, then the result is Invalid. For division, if a user divides anything by zero, the result will display, invalid/Infinity as the answer is undefined. 

How was it Built? And Challenges :

This project was built using JavaFX. Since this was my first time using JavaFX, setting up the JavaFX project on my IDE was pretty difficult especially on my Mac when it had to do with Building Paths to access my libraries as my calculator GridPane wouldn't display. It took a very long time until I switched to Windows.  Some challenges while programming was the Error Handling, such as when a user enters anything other than floating point numbers such as characters like a, b, c. First I had to create a try catch to catch the NumberFormatException to make the answer invalid. When it came to Division, despite the NumberFormatException, another problem was that dividing by zero makes the solution undefined making it an ArithmeticException. I had to use two try catches to first catch the ArithmeticException and another one for the NumberFormatException. Displaying the result and formatting the result was pretty hard as well as at first it didn't display as well as while I fixed the displaying of the result, it overlapped with the Label, so I had to change the row/col numbers. 

Accomplishments:

I am very proud that my first application was a success as it was able to perform all the 4 basic operations: add, subtract, multiply, and divide but also catch all the error handlings such as the NumberFormatException and ArithmeticException. 

What Have I Learned?:

Since this was my first time actually making an Application, I was excited, but also had to learn a lot about JavaFX. I learned how to set up a JavaFX project in Windows/Mac and how to Build Paths to access the libraries. I also learned how the implementation of a JavaFX application works, especially how the GridPane works and how to set up the setOnMouseClicked used to call the calculation functions. I also learned how placing nodes would affect the display of the calculator and how to add buttons for each operation. 

What Next? Any Improvements?:

My next goal is to perform more options such as finding the square root of a number, squaring a number, but later on add the trigonometry functions. In the future, instead of the user having to enter two numbers, I would like to also increase the amount of textfields so the user can enter more than two numbers to compute averages, etc. 

Built With

Share this project:

Updates