This a calculator capable of performing basic math operations. It runs through console, asking user for inputs, then performing the chosen operation and printing it on screen.
After realizing I've mostly solved programming logic problems and followed tutorials, I missed having a program that that did not answer a given question or follow a given solution. So I thought for a while "What am I capable of doing now?" ,"What can I do to test myself?","Which program would have room for improvements?" , and then the present idea was born: "A calculator!".
So, why a calculator? As you may imagine, it fits quite well the previous questions. "Calculator" is something with a very large variety of possiblities. It can be your everyday shop assistant, it could be a tool for doing you taxes, or it could be the helping hand for your calculus and geometry problems. "Calculator" could be anything between somenething that adds 1 to 1 to a tool that helps you to figure out enthropy -- And that is truly Amazing!
I'm actually quite happy about this! it can be anything my skills allow me to achive: I wonder what it'll have become a year from now. Now, let's proceed to the fabrication process!
Briefing about what I did and you're about to read:
- Bullet points about a general calculator;
- Diagram about generic calculator
- Diagram clarifying how my calculator would be done;
- Pseudocode
- Coding in Java
I started taking notes,to figure out what to do: "How to a calculator?", "What a calculator does?". From these questions I made up list:
- Receives number inputs;
- Receives an input that defines an operation;
- Does the operation;
- Displays operation's result.
Then I proceded to make a basic diagram, as I want to practice documentation and design,to make my own ideias more clear and to be able to present them better:
Then I wrote a pseudocode representing the program:
Program"Caculator"
Var
float: numberX, numberY, result
char: operator
Start
print("Insert the first number: )
scan(numberX)
print("Choose a valid operation ( + , - , * , / ) : ")
scan(operator)
print("Insert the second number: )
scan(numberY)
if ( operator == '+' ) {
result = numberX + numberY
} else if ( operator == '-' ) {
result = numberX - numberY
} else if ( operator == '*' ) {
result = numberX * numberY
} else if ( operator == '/' ) {
result = numberX / numberY
} else {
print("You must insert a valid operation ( + , - , * , / )")
}
print( numberX, operator, numberY, " = ", result)
End
At least, I coded the algorithm using Eclipse. This process may look long and reduntant, but it was actually sketched on papper, so the time spent was thinking-related and not tool-related. That being said, when I started coding in Java I had a very clear direction in mind, barely faced errors, the ones I faced were typing related not design related, and I'm sure this will make a great difference as I enage in more complex projects and as this very project complexity incresases.
Not only that, I found out it is actually satisfying to be able to design using diagrams. I tried in the past some times, but I failed to make something understandable and useful: this was the first time I actually felt that I was in fact constructing a solution and making it easy to follow using diagrams. I believe practicing this will be very helpful when colaborating (and also some time from now, when I come back to my own code, I feel that sensation of "Jesus, what does this means? How does it even runs!?" will be greatly diminished).
If you read all the way up-down to here, I'm truly grateful. Thanks for your time, I hope you have a wonderful day!