Monday Instructions

Today we’re going to work to complete the ComplexAdder that we started Wednesday last week.  These instructions are contingent on having the ComplexAdder application from last week.  If you do not have it, simply go back to the Wednesday Notes and Instructions, follow the instructions, and then proceed.

  1. Open the ComplexAdder project in Visual C# Express
  2. We want to get to the “code behind” page of the Form1.cs.  If it is not open already, open Form1.cs and hit F7, or right-click and select View Code.
  3.  In order to finish our adding function, we need to have a variable to store a number.  Between the declaration of the class and the constructor, create a numberBuffer property that is an int.  It should look like this:
public partial class Form1 : Form
 {
 public int numberBuffer { get; set; }
public Form1()
 {
 InitializeComponent();
 }

After getting the numberBuffer in place and making sure the application worked, we launched into use cases.  We need to know what happens to the numberBuffer and the entryBox when the plus and equals buttons are pushed, as well as what happens to those objects when the number buttons are pushed.  Here is what we came up with:

use case 1:

User enters 1, then hits the + button, then hits 2 and hits the equals button

numBuffer: starts with 0,
starts with value –> 0
after hitting 1 –> 0
after hitting + –> 1
after hitting 2 –> 1
after hitting = –> 0

entryBox:
starts showing –> 0
after hitting 1 –> 1
after hitting + –> 1
after hitting 2 –> 2
after hitting = –> 3

Use case 2:
user hits 1, then hits +, then hits 2, then hits +, then hits 2, then hits =
numberBuffer
 starts with value --> 0
 after hitting 1 --> 0
 after hitting + --> 1
 after hitting 2 --> 1
 after hitting + --> 3
 after hitting 2 --> 3
 after hitting = --> 0
entryBox
 starts by showing --> 0
 after hitting 1 --> 1
 after hitting + --> 1
 after hitting 2 --> 2
 after hitting + --> 3
 after hitting 2 --> 2
 after hitting = --> 5

In short, every time the plus button is pushed, the numberBuffer gets updated with the sum of the current numberBuffer and the current entryBox values, and the entryBox is updated to show the sum.  Whenver the equals button is pushed, the sum is displayed, and the numberBuffer is cleared back to 0.  Whenever a number button is pushed, only the entryBox is changed.

Next instructions:

Update the plus button to follow these rules

Update the equals button to follow these rules

Remember that to add two numbers, you’ll need to convert the entryBox.Text to an int using the int.Parse() or int.TryParse() methods.

 

Leave a Reply

Your email address will not be published. Required fields are marked *