/Java-Calculator-v2

A console based calculator.

Primary LanguageJava

Java Calculator v2

This was completed as part of a skills demostration for a college class. The following were the requirements:

"Write a Java program that implements a simple calculator. It will contain 1 java class called Calculator.java. The class will take 2 integers and an operator (+ - / *) as input from the command line.

Identify all the data types required and declare the required variables.

Use an if/else (or switch) statement to determine which operator the user entered, and for each case perform the operation (add, subtract, divide or multiply) and write the result out to the command line.

Use casting to ensure that data loss/memory wasteage does not occur in your program, for example:

  1. When you divide 10 by 4. The answer is 2.5 (a float) not 2 (an integer)).
  2. When you add, subtract or multiply two integers that produce a result larger than 2147483647 (or smaller than ‐2147483647) you need to cast to a long."