A
A
Azamat Aktemirov2020-02-12 21:06:59
Java
Azamat Aktemirov, 2020-02-12 21:06:59

What logical classes should a simple calculator be divided into from an OOP point of view?

Good day to all! Guys, please tell me what logical classes a primitive calculator ( +, - , * , /) can be divided into from the point of view of OOP, you need to complete a test task, I did it in one class - they asked to divide it. Thank you all very much)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oksana ..., 2020-02-12
@azpwnz

You have only 4 actions, so you can make the App classes (it has a main method to launch the application and get a string from the console), a Parser class to “parse” the string into arguments and an operator (math.action), and the last Calculator class (takes arguments and mathematical operator), performs actions and displays the result.

D
Denis Zagaevsky, 2020-02-12
@zagayevskiy

Well, without knowing what you wrote there, you can’t say.
If there is a calculation of complex expressions, it is logical to select Tokenizer (splits the string into tokens) Parser (parses the expression presented as a list of tokens), Calculator (calculates the parsed syntactically correct expression, for example, using the Polish inverse notation).
If there is interactive (input / output to the console, windows), it makes sense to make MVP or MVC.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question