if (operation.equals("+"))
{
SimpleCalculator simpleCalc = new SimpleCalculator();
double result = simpleCalc.add(numOne, numTwo);
System.out.println("The result is " + result);
}
else if (operation.equals("-"))
{
SimpleCalculator simpleCalc = new SimpleCalculator();
double result = simpleCalc.substract(numOne, numTwo);
System.out.println("The result is " + result);
}
You coluld simplify this block by removing the redundant lines of code. And you do not need an instance of
SimpleCalculator
as all its methods are
static
.
double result =0.0;
if (operation.equals("+"))
{
result = SimpleCalculator.add(numOne, numTwo);
}
else if (operation.equals("-"))
{
result = SimpleCalculator.substract(numOne, numTwo);
}
System.out.println("The result is " + result);
For better training in Java I recommend
The Java™ Tutorials[
^].