What makes an object oriented calculator unsusable?

What makes an object oriented calculator unsusable?

And there’s no longer a need for the Calculator to permanently store the operand1, operand2, and operation as fields. You’re mixing computation and output ( System.out.println () ) in makeCalculation (). That makes your otherwise good calculator unsusable in e.g. a GUI or a web application.

How to use strategy in a Java calculator?

You can use the operations (+,-,/,*) by strategy. And you can give this strategy as a context to the calculate method.

How to create a new calculator in Java?

You are creating a new Calculator for every calculation you are doing (and together with the Calculator, new Operation s). I’d have one Calculator instance, filling the operationMap the way you did, but not taking the double operand1, double operand2, char operation parameters in the constructor.

Do you need operand1 and operand2 in a calculator?

This way the Calculator’s initialization needs to run only once, and then he’s ready for as many calculations as you want – just like a hardware calculator that you typically use for more than one calculation. And there’s no longer a need for the Calculator to permanently store the operand1, operand2, and operation as fields.

How to create a console calculator in Java?

I’d have one Calculator instance, filling the operationMap the way you did, but not taking the double operand1, double operand2, char operation parameters in the constructor. I’d move them to the makeCalculation () method, changing that to makeCalculation (double operand1, double operand2, char operation).

Which is a formal definition of object oriented programming?

N ow that we understand what classes and objects are, this formal definition of object-oriented programming makes much more sense:

What makes a Java calculator unsusable in a web application?

You’re mixing computation and output ( System.out.println () ) in makeCalculation (). That makes your otherwise good calculator unsusable in e.g. a GUI or a web application. The error handling in makeCalculation () should throw an exception if something goes wrong instead of printing something to System.out.