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