1. ## calculator Class?

I need to create a calculator class for my basic calculator application that will implement the functions of the Calculator?
The design of the calculator class should be in this

This is what I have so far, am so confused?
PHP Code:
``` public class Calculator     {         private decimal currentValue;         public Calculator()         {         }         public Calculator(decimal currentValue)         {             this.CurrentValue = currentValue;         }         public decimal CurrnetValue         {             get             {                 return currentValue;             }             set             {                 currentValue = value;             }         }         public decimal Add(decimal operand1, decimal operand2)         {             return operand1 + operand2;             }         public decimal Subtract(decimal operand1, decimal operand2)         {             return operand1 - operand2;         }         public decimal Multiply(decimal operand1, decimal operand2)         {             return operand1 * operand2;             }                  public decimal Divide(decimal operand1, decimal operand2)         {             return operand1 / operand2;             }     } }  ```

2. ## Re: calculator Class?

Why not use an automatic property?
csharp Code:
`public decimal CurrentValue { get; set; }`

Also, instead of 2 parameters for what you've got, you should be utilizing the CurrentValue and having the first and only param for each of these functions deal with the mathematical operations with CurrentValue and that param instead. And setting CurrentValue in the process. The way you have it there's no way to keep track of the CurrentValue for this instance.

3. ## Re: calculator Class?

I think you have misunderstood. From my reading of your assignment, you need to maintain state inside the class, so that it would be used something like this:

csharp Code:
`Calculator calculator = new Calculator();// calculator.CurrentValue == 0calculator.EnterValue(5);// calculator.CurrentValue == 5calculator.Add();// calculator.CurrentValue == 0 (? probably)calculator.EnterValue(3);// calculator.CurrentValue == 3calculator.Equals();// calculator.CurrentValue == 8`

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured