1
00:00:00,570 --> 00:00:02,270
Hello In this lecture.

2
00:00:02,280 --> 00:00:14,440
We are going to wrap up the code for the calculator and hookup what's left to make the calculator work.

3
00:00:15,110 --> 00:00:26,540
We need a way to tell when an operator has being clicked at the moment there is no way of telling if

4
00:00:26,540 --> 00:00:33,420
I click this plus button or the multiplication there is no way of telling it has been clicked.

5
00:00:33,740 --> 00:00:40,520
So what we're going to do we're going to create a variable that will store that value.

6
00:00:40,520 --> 00:00:44,950
I've already created a variable I'll just gonna let you know where it is.

7
00:00:44,960 --> 00:00:52,890
So here I've created a variable called is operator clicked.

8
00:00:53,630 --> 00:00:58,610
And by default I've set it to false which means it hasn't been clicked.

9
00:00:58,610 --> 00:01:00,890
It's a bull data type.

10
00:01:00,900 --> 00:01:04,930
That means where the bull is either true or false.

11
00:01:04,940 --> 00:01:12,210
So when the button has not been clicked it will be false.

12
00:01:12,220 --> 00:01:19,780
I also need to be able to capture when the button or the operator has been clicked.

13
00:01:19,790 --> 00:01:24,260
So when any of the operator buttons has been clicked I want to capture that.

14
00:01:24,450 --> 00:01:27,230
I've already defined the value here as a bull.

15
00:01:27,260 --> 00:01:34,600
So all I need to do is just reuse that variable and change the value to force.

16
00:01:34,600 --> 00:01:41,360
And the way we're going to specify I'm going to specify that inside the Click event

17
00:01:44,430 --> 00:01:50,190
so inside the Operator We've got an event for the operator.

18
00:01:51,060 --> 00:01:58,400
So here inside the operator click event I have specified this variable here.

19
00:01:58,470 --> 00:02:06,000
So when the button I know the operator has been clicked it will be specified here that that value then

20
00:02:06,000 --> 00:02:11,790
changes to true which means it has been clicked.

21
00:02:11,790 --> 00:02:14,940
We also need to do the same for each of these numbers.

22
00:02:14,940 --> 00:02:22,120
So we need to know when they're being clicked and when they have not been clicked.

23
00:02:22,140 --> 00:02:27,510
So we'll do a similar operation to what we did with the operator.

24
00:02:27,510 --> 00:02:29,140
So go back into code.

25
00:02:29,380 --> 00:02:33,000
I've already specified this.

26
00:02:33,000 --> 00:02:41,070
So we'll specify this value inside the button click event with the operator what we specified it inside

27
00:02:41,070 --> 00:02:42,670
the operator click event.

28
00:02:42,670 --> 00:02:46,680
So we'll look for the button click event.

29
00:02:46,680 --> 00:02:49,420
So this is the button click event.

30
00:02:49,610 --> 00:02:51,960
And this is where I specified it.

31
00:02:52,020 --> 00:03:02,010
So when the button is addressed to when it hasn't been clicked the default value will be false.

32
00:03:02,010 --> 00:03:07,290
I have the if statement here that we defined Alia.

33
00:03:07,310 --> 00:03:12,420
I have actually added another operator.

34
00:03:12,420 --> 00:03:14,300
This here is called the all.

35
00:03:14,700 --> 00:03:22,110
So I've added another condition to this if statement saying that if the result text box is pretty close

36
00:03:22,110 --> 00:03:35,070
to zero or this operator click value which is this variable here here too is looking for these two conditions.

37
00:03:35,070 --> 00:03:41,760
Either this or that it will clear the box because previously if you clicked on this it doesn't clear

38
00:03:41,760 --> 00:03:42,140
it.

39
00:03:42,150 --> 00:03:47,970
So that's what this extra this value has called a pipe.

40
00:03:48,090 --> 00:03:49,220
It means all.

41
00:03:49,560 --> 00:03:54,270
So as I'll check for this condition and also check for this condition.

42
00:03:54,270 --> 00:03:57,120
And then it will clear the box.

43
00:03:57,270 --> 00:04:01,620
It will use this clear box this clear method to clear what's in there.

44
00:04:02,280 --> 00:04:08,910
So again we've already specified when the operator all is clicked if he's not clicked it will be false

45
00:04:09,000 --> 00:04:12,310
when he's clicked a becomes true.

46
00:04:12,330 --> 00:04:21,790
So here on court and if statements have implemented saying if the button the text is strictly equal

47
00:04:22,640 --> 00:04:29,970
to the period which is dot it will execute this code.

48
00:04:29,970 --> 00:04:40,110
If the result if it is the result if the text this exclamation means does not the result box does not

49
00:04:40,110 --> 00:04:44,100
contain this and it silences exclamation why miss it.

50
00:04:44,130 --> 00:04:46,760
It means does not a thing.

51
00:04:46,770 --> 00:04:52,400
If this variable does not contain this this will happen.

52
00:04:52,410 --> 00:05:00,360
The result does result box or text is variable will display the text on the button.

53
00:05:00,360 --> 00:05:05,970
If that condition is not met if the first condition is not met it will do this.

54
00:05:05,970 --> 00:05:08,260
It will show this piece of code.

55
00:05:08,430 --> 00:05:15,510
It will show this and the text which is basically the same part of this.

56
00:05:15,510 --> 00:05:21,950
So within each statement if the first condition is true to execute what's in this to execute this if

57
00:05:21,950 --> 00:05:33,460
it is false it will execute what's in the else statement here inside the operator or method.

58
00:05:33,540 --> 00:05:41,770
We have an if statement with checks if the result value is not equal to zero it will execute this code.

59
00:05:42,020 --> 00:05:52,700
The equal to button dot click it will perform that if the operator or click button it will execute that.

60
00:05:52,710 --> 00:05:57,990
So if the result is not zero to execute this piece of code that's basically what that is saying.

61
00:05:58,520 --> 00:06:00,680
All right.

62
00:06:00,690 --> 00:06:04,810
If this condition is false.

63
00:06:04,810 --> 00:06:07,540
It will execute this piece of code.

64
00:06:07,600 --> 00:06:09,980
That's basically what an if statement does.

65
00:06:10,090 --> 00:06:14,260
If one condition is true it executes was in that part of the code.

66
00:06:14,290 --> 00:06:20,410
If it's not it will execute what's in the else statement.

67
00:06:20,410 --> 00:06:24,040
So let's scroll down and see what else we've done.

68
00:06:24,040 --> 00:06:32,610
And here we've got the operator collect a the button texts and we got the result of this result.

69
00:06:32,620 --> 00:06:39,400
Value here equals so that we've already gone through that piece of code.

70
00:06:39,400 --> 00:06:47,890
So this is the switch statement for the equals two button.

71
00:06:48,090 --> 00:06:56,910
So we are basically done now and so all the code just check in true to make sure we've not left anything

72
00:06:57,000 --> 00:06:59,090
out.

73
00:06:59,180 --> 00:07:08,250
OK so we are good to fire run the application now the calculator should work.

74
00:07:08,250 --> 00:07:10,770
So let me just go through the code.

75
00:07:11,110 --> 00:07:15,870
Make sure nothing has been left out.

76
00:07:16,550 --> 00:07:17,140
Okay.

77
00:07:17,160 --> 00:07:20,490
It looks good so far I can't see any errors.

78
00:07:20,490 --> 00:07:22,240
So that's a good sign.

79
00:07:22,260 --> 00:07:28,400
One thing with widgets to do if there's any arrows in your code e to complain and tell you about it.

80
00:07:28,480 --> 00:07:33,360
So all right so I think we good to go.

81
00:07:34,110 --> 00:07:34,700
All right.

82
00:07:34,710 --> 00:07:35,430
That's fine.

83
00:07:35,430 --> 00:07:43,030
So I'm just gonna run the code and click on Start and just perform some basic calculation.

84
00:07:43,260 --> 00:07:51,330
So do seven times seven plus forty nine.

85
00:07:51,330 --> 00:08:04,240
Clear that and do five minus two that's three clear that I do six.

86
00:08:04,320 --> 00:08:05,730
Divide by

87
00:08:08,460 --> 00:08:10,200
two.

88
00:08:10,260 --> 00:08:11,290
Give me three.

89
00:08:12,500 --> 00:08:16,920
And I do two point five.

90
00:08:16,920 --> 00:08:20,550
Lost two point five.

91
00:08:20,610 --> 00:08:21,450
That's five.

92
00:08:21,780 --> 00:08:29,040
So the calculator is working all the operator sides are working the number bottoms up work in the clear

93
00:08:29,370 --> 00:08:31,350
button is also working.

94
00:08:31,950 --> 00:08:34,290
So that is it.

95
00:08:34,290 --> 00:08:39,880
We have successfully created a basic working calculator.

96
00:08:39,900 --> 00:08:46,980
Feel free to play around if any aspects of this project you do not understand.

97
00:08:46,980 --> 00:08:48,710
Please feel free to contact me.

98
00:08:48,730 --> 00:08:52,310
I'll be more than happy to explain further.

99
00:08:52,320 --> 00:08:53,160
Thanks very much.

100
00:08:53,160 --> 00:08:54,870
Take care and bye for now.
