Building a Simple CLI Calculator App in Java

Matt Cummings
The Startup
Published in
8 min readFeb 3, 2020

--

I recently started to pick up Java since I don’t have experience with writing static languages. Using Codecademy’s free courses, I’ve picked up some fundamentals and saw that their premium version had users build a basic calculator with Java. Now, I’m trying to save as much money as I can, so while I couldn’t be guided through making it, it’s definitely an easy enough exercise to do on your own.

This article assumes you know a little bit about the basics of Java, like how to set up classes and their instance fields and methods. There are also some constraints and improvements we could add to this app, discussed in the Limitations and Improvements section.

Topics covered in this article are:

  • Composing basic app setup (public class, constructor, etc.)
  • Creating basic mathematical functions in Java
  • Use of the Scanner class to receive input
  • Conditionals and switch statements
  • The basics of typecasting
  • Implementing recursion

You can follow along with the repo here: https://github.com/TimeSmash/java-calculator

Setting up the Basics

This app gets input from a user, and we’ll need the Scanner class to accept…

--

--