0:00:00.460,0:00:01.323
Let's add the code now to our app.
0:00:01.323,0:00:05.710
We're going to start by calculating[br]the base price of a drink.
0:00:05.710,0:00:07.910
The base price is composed of two parts.
0:00:07.910,0:00:11.310
The price of the coffee,[br]which is $5 plus any toppings.
0:00:11.310,0:00:13.420
So $1 for whip cream,[br]or $2 for chocolate.
0:00:13.420,0:00:15.523
We're going to take this base price, and
0:00:15.523,0:00:19.360
then we're going to multiply it[br]by the quantity of cups ordered.
0:00:19.360,0:00:21.080
That will brings us to[br]the total order price.
0:00:22.640,0:00:24.930
Let's calculate the price for[br]a sample order,
0:00:24.930,0:00:28.770
where the user wants 3 cups of coffee[br]with whipped cream, like this.
0:00:28.770,0:00:32.409
The goal of this course is not to test[br]your math skills so let's walk through
0:00:32.409,0:00:35.210
the calculation together to make[br]sure that you understand it.
0:00:35.210,0:00:38.860
The real goal will be for[br]you to translate this logic into code.
0:00:38.860,0:00:42.910
In this sample order the user wants[br]3 cups of coffee with whipped cream,
0:00:42.910,0:00:44.000
like this.
0:00:44.000,0:00:48.070
First, we can start off by calculating[br]the base price of 1 cup of coffee.
0:00:48.070,0:00:53.180
We start with $5 for the coffee cup[br]plus $1 for the whipped cream topping.
0:00:53.180,0:00:55.390
That brings us to $6 per cup.
0:00:55.390,0:00:57.580
Then, we need to find[br]the total order price.
0:00:57.580,0:01:02.878
Since the user ordered 3 cups of coffee,[br]we multiply $6 per cup times 3 cups.
0:01:02.878,0:01:07.010
That equals $18 total for[br]the whole order.
0:01:07.010,0:01:09.650
In this sample order,[br]we have 2 cups of coffee and
0:01:09.650,0:01:14.840
each cup has whipped cream topping and[br]chocolate topping, like this and this.
0:01:14.840,0:01:16.860
First, we calculate[br]the base price of 1 cup.
0:01:18.150,0:01:21.090
A cup of coffee costs $5,[br]and then we add $1 for
0:01:21.090,0:01:23.620
whipped cream and $2 for chocolate.
0:01:23.620,0:01:28.540
That brings us to a total of 5,[br]6, 7, 8, $8 per cup.
0:01:28.540,0:01:32.830
Then we find the total order price since[br]the user ordered 2 cups of coffee.
0:01:32.830,0:01:37.140
We take the base price of $8 per[br]cup of coffee times 2 cups and
0:01:37.140,0:01:40.200
that brings us to $16 total for[br]the whole order.
0:01:41.230,0:01:42.580
This is what our app should look like.
0:01:43.640,0:01:44.772
We can enter in a name,
0:01:44.772,0:01:49.010
choose a whipped cream topping and[br]then change the quantity to 3.
0:01:49.010,0:01:52.840
If we hit the Order button,[br]we expect the price to change to $18.
0:01:54.080,0:01:55.180
And there it is.
0:01:55.180,0:01:58.450
This is exactly what we[br]calculated earlier by hand.
0:01:58.450,0:02:01.680
If I add the chocolate topping,[br]change the quantity to 2.
0:02:01.680,0:02:04.030
Then the total price becomes $16,
0:02:04.030,0:02:08.740
also just like we calculated where[br]we have $8 per cup of coffee.
0:02:08.740,0:02:12.050
Now, go ahead and plan out the steps[br]that you need to do in order to add this
0:02:12.050,0:02:13.590
functionality to our app.
0:02:13.590,0:02:16.300
I wrote down the price of[br]the toppings here for reference.
0:02:16.300,0:02:18.910
And here's a screen shot of[br]what the app should look like
0:02:18.910,0:02:20.800
with the adjusted price here.
0:02:20.800,0:02:24.910
After you've planned out the steps then[br]go ahead and implement this in your app.
0:02:24.910,0:02:27.560
Then, can you tell me what[br]method did you end up modifying?