Friday, August 8, 2014

Calculator Exercise

Calculator


A long time ago when I was doing Visual Basic development, I create a programming exercise that I used to help teach new developers Visual Basic.  The program is a simple calculator.  It allowed me to teach people how to create VB forms, add and manipulate controls, and write some logic that needed data from the UI and had to put data back into the UI.

This project was also great for teaching a new language because it wasn't dependent on databases, file systems, or external APIs.  I have recently re-created this exercise for a new developer on my team, and for myself to work on learning Javascript.  So that I don't have to re-create this again, I'm writing up the project here so I have it.

Exercise

Create a calculator that can do basic arithmetic with two operands.

  • The calculator should have a display area.
    • The display area should show zero if no number has been entered.
    • Once a number is entered, that number is displayed.
    • Once an operator is selected, the number displayed should be zero until the next number is entered.
  • Users can enter numbers by clicking the number buttons, just like a physical calculator.
    • The user should be able to use digits 0 - 9 and the decimal point.
  • The basic arithmetic operations of addition, subtraction, multiplication, and division are allowed.
  • Integers and decimal numbers can be entered.
  • The user should be able to click a "clear" button to reset the operation and empty the display area.
UPDATE:  Here is my HTML/Javascript implementation:  https://github.com/haled/CodingTraining/tree/master/gui_calculator.

No comments:

Post a Comment