I wrote codes to build a four function calculator using Java in my early days of coding. The program provide the calculator to the user, and user can type the number 1-4 to choose the type of calculator function. Input validation is implemented in this program, it checks if the user type the numbers from 1-4. The program will tell the user if he didn’t input the number from 1-4, then it will ask the user if he wants to calculate again.
I implemented the input validation using if/else statements. I also implemented four different functions for the different type of calculations chose by the user. I didn’t choose to use a switch statement for the input validation because I didn’t learn about the switch statement when I coded this project. Reflecting back on this project, using a switch statement will shorten the amount of code written. I could’ve also just shorten the code for the calculation by using one function, and use the switch statement within the function. I practiced coding with function and input validation in this Calculator program, and it was helpful to build my Java language skill.
Source code to be made available soon