Advertisement
English transcript
We showed you how to do the first two steps.
If you still need help with those, that's no problem at all,
you can just watch the previous video again.
Now I'll show you how to update variables within the decrement method.
We ask you to initialize the quantity variable to 1, and
update it down to 1 cup of coffee.
I'm going to make the code change in the MainActivity.java file in
the decrement method.
We're creating a quantity variable and initializing it to 2.
Then I'm going to add another line of code that updates the quantity variable
to be 1.
And lastly, I displayed this new value to the screen.
Let's run the app to check that it works.
If I hit the minus button, then it decreases down to 1.
I can add a breakpoint here and
run the debugger to show that the quantity variable is being updated.
I'm going to click on this debug tab to open the debug pane.
I click on the minus button to trigger the breakpoint here, and
then step through each line of code.
At this point, the first sign has executed, so
the quantity variable has a value of 2, and then it changes to a value of 1.
And then I can just resume the app and
the app should update to have a quantity of 1.
And there it goes.
All right, I think we've nailed the concept of how to update an integer
variable to a new number and verify its value in the debugger.
This is still limited, though.
There are actually other ways to update a variable aside from just
setting a fixed literal value.
If you still need help with those, that's no problem at all,
you can just watch the previous video again.
Now I'll show you how to update variables within the decrement method.
We ask you to initialize the quantity variable to 1, and
update it down to 1 cup of coffee.
I'm going to make the code change in the MainActivity.java file in
the decrement method.
We're creating a quantity variable and initializing it to 2.
Then I'm going to add another line of code that updates the quantity variable
to be 1.
And lastly, I displayed this new value to the screen.
Let's run the app to check that it works.
If I hit the minus button, then it decreases down to 1.
I can add a breakpoint here and
run the debugger to show that the quantity variable is being updated.
I'm going to click on this debug tab to open the debug pane.
I click on the minus button to trigger the breakpoint here, and
then step through each line of code.
At this point, the first sign has executed, so
the quantity variable has a value of 2, and then it changes to a value of 1.
And then I can just resume the app and
the app should update to have a quantity of 1.
And there it goes.
All right, I think we've nailed the concept of how to update an integer
variable to a new number and verify its value in the debugger.
This is still limited, though.
There are actually other ways to update a variable aside from just
setting a fixed literal value.