WEBVTT

0
00:00.140 --> 00:01.430
You've just been hired.

1
00:01.430 --> 00:02.630
Congratulations.

2
00:02.630 --> 00:05.840
But first, there's the matter of coffee.

3
00:05.840 --> 00:10.280
We all know that programmers can't work unless they're loaded up on coffee.

4
00:10.280 --> 00:15.650
So your company has asked you to create the code for a coffee machine.

5
00:16.070 --> 00:22.160
Now, you very cleverly go online and look at the other coffee machines, and you notice that it only

6
00:22.160 --> 00:25.910
costs $230 to buy a coffee machine,

7
00:25.910 --> 00:27.380
but you're not going to cheat,

8
00:27.380 --> 00:29.900
you're going to create everything from scratch.

9
00:29.950 --> 00:34.840
And luckily, we don't actually have to build the hardware because we're programmers, right?

10
00:34.840 --> 00:42.190
But we're going to use this real life coffee machine as the inspiration for our virtual coffee machine,

11
00:42.280 --> 00:45.370
noting the features and the capabilities.

12
00:45.370 --> 00:47.470
So what does it say?

13
00:47.680 --> 00:54.310
I found some wonderful graphics on here, which tells me that there are three hot flavors, which I'm

14
00:54.310 --> 00:56.400
guessing are these three buttons.

15
00:56.400 --> 01:03.750
It's coins operate, which I think they mean it's coin operated, and there's not much else that it

16
01:03.750 --> 01:04.590
can do.

17
01:04.620 --> 01:09.810
Let's take this example and we're going to make a digital version of it.

18
01:09.810 --> 01:12.420
We're going to create our own coffee machine.

19
01:12.420 --> 01:18.030
And the first step we need to replicate is the ability to make three hot flavors.

20
01:18.030 --> 01:24.460
So the flavors we're going to make are one Espresso, two Latte, and three Cappuccino.

21
01:24.550 --> 01:28.480
Here are the recipes for these three types of drinks,

22
01:28.480 --> 01:33.730
each of them requires a different quantity of water, a different quantity of coffee, and a different

23
01:33.730 --> 01:34.990
quantity of milk.

24
01:34.990 --> 01:38.350
And they also each have a different price.

25
01:38.560 --> 01:43.450
We're going to be modeling all this data in our coffee machine program as well.

26
01:43.450 --> 01:49.670
But luckily for you, in the starting code, I've already included all of this data inside a dictionary,

27
01:49.670 --> 01:54.260
so you don't have to remember this, although it might help if you're at home and you decide that you

28
01:54.260 --> 01:57.620
really wanted a latte instead of your usual black coffee.

29
01:57.650 --> 02:02.270
Now, in addition, the coffee machine has some resources that it has to manage.

30
02:02.270 --> 02:09.560
So it starts out with 300 ml of water in the tank, 200 ml of milk, and 100g of coffee.

31
02:09.590 --> 02:14.510
The second feature of our coffee machine is that it's coin operated.

32
02:14.510 --> 02:17.510
So we're going to be using American coins.

33
02:17.510 --> 02:23.330
And they have four types of coins the Penny, the Nickel, the Dime, and the Quarter.

34
02:23.360 --> 02:25.970
They used to also have the Dollar as a coin,

35
02:25.970 --> 02:28.280
but a few years ago they stopped minting that.

36
02:28.280 --> 02:29.300
So we're not going to count it,

37
02:29.300 --> 02:31.940
and it probably means one less if statement for us.

38
02:31.940 --> 02:35.270
Notice what each of these coins are worth.

39
02:35.270 --> 02:41.910
The penny is worth a cent, the nickel worth $0.05, and the dime $0.10, and the quarter is a quarter

40
02:41.910 --> 02:42.720
of a dollar.

41
02:42.750 --> 02:48.210
These represented in decimal values would look something like this.

42
02:48.990 --> 02:50.970
Now here's the important part,

43
02:50.970 --> 02:55.260
let's think about what our program requirements are if we break it down.

44
02:55.680 --> 02:59.580
One we need our coffee machine to be able to print a report.

45
02:59.580 --> 03:05.200
It needs to be able to tell us what resources it has left, how much water has left, how much milk,

46
03:05.200 --> 03:06.070
et cetera.

47
03:06.100 --> 03:11.590
So let's say that we wanted a report on all the resources that the machine has.

48
03:11.620 --> 03:16.960
All we have to do is type report and we can see all the resources we have.

49
03:17.380 --> 03:23.290
Now, in addition to being able to print a report, we also want to be able to check that the resources

50
03:23.290 --> 03:26.410
are sufficient when the user orders a drink.

51
03:26.920 --> 03:30.190
Now let's say that the user decided to order a latte.

52
03:30.520 --> 03:37.270
It asks me to insert some coins and then it gives me the change and it gives me the latte.

53
03:37.300 --> 03:43.480
But now if I check the report, I can see that I've only got 100 ml of water left,

54
03:43.480 --> 03:49.750
and I know from the previous slide that a latte and a cappuccino is going to need more than that amount

55
03:49.750 --> 03:50.560
of water.

56
03:50.570 --> 03:54.710
So let's see what happens if I go ahead and order a cappuccino.

57
03:54.800 --> 03:57.860
It says, "Sorry, there's not enough water."

58
03:57.860 --> 04:05.750
So our program is able to look through all the resources that the machine has, checks it against the

59
04:05.750 --> 04:12.770
recipe of the drink that we're trying to make, and tells the user if there is insufficient water or

60
04:12.770 --> 04:14.300
if there's insufficient milk,

61
04:14.300 --> 04:20.190
and as long as one of the resources is insufficient, then it can't make the drink and it gives the

62
04:20.190 --> 04:21.540
feedback to the user.

63
04:21.960 --> 04:27.930
Now, as you saw before, our program also needs to be able to process coins because our machine is

64
04:27.930 --> 04:33.900
coin operated, so no fancy contactless payment or pay with your Apple Watch,

65
04:33.900 --> 04:34.500
none of that.

66
04:34.500 --> 04:36.120
We've only got coins.

67
04:36.150 --> 04:43.260
When we order something, it should ask us to insert coins, and it's going to ask for the quantity

68
04:43.260 --> 04:44.850
of each type of coin.

69
04:44.850 --> 04:47.940
So let's say that I insert one of each.

70
04:47.940 --> 04:54.540
Then in this case, there's actually not enough money to cover my drink, and it refunds the money and

71
04:54.540 --> 04:55.920
doesn't give me a drink.

72
04:56.010 --> 05:03.480
But on the other hand, if I do insert enough money, then it should be able to calculate how much money

73
05:03.480 --> 05:09.580
all of these coins are worth and then calculate the amount of change based on the cost of my drink,

74
05:09.580 --> 05:13.300
and then it should hand me my drink, and tell me to enjoy.

75
05:13.930 --> 05:19.930
So in addition to being able to process the four types of coins, calculating the actual monetary value

76
05:19.930 --> 05:25.210
based on the number of coins, it should also check that the transaction is successful, that the user

77
05:25.210 --> 05:30.340
didn't try to hoodwink us by not giving enough coins and asking for a drink.

78
05:30.400 --> 05:35.630
So if they haven't inserted enough coins, then we're just going to refund them and tell them, "Sorry,

79
05:35.630 --> 05:38.960
that's not enough money" and not give them their drink.

80
05:38.960 --> 05:44.360
But if the transaction was successful, then we're going to make the coffee,

81
05:44.360 --> 05:49.640
and in the process of making the coffee, we're going to have to deduct the resources.

82
05:49.670 --> 05:54.110
Notice how every time we make a drink say, in this time we made a latte,

83
05:54.500 --> 05:58.530
and previous to the latte we had 300ml of milk.

84
05:58.530 --> 06:04.050
But after the latte, when we asked for the report, you can see that the water has been reduced, the

85
06:04.050 --> 06:08.850
milk has been reduced, the coffee has been reduced, and the money has been put into the coffers.

86
06:09.300 --> 06:15.780
This program, even though it seems simple, just a simple digital version of a coffee machine, it

87
06:15.780 --> 06:18.510
actually has quite a few requirements.

88
06:18.540 --> 06:26.280
Now I've created a detailed program specification for you as a PDF file, which you can download in

89
06:26.280 --> 06:27.810
the Course Resources,

90
06:27.810 --> 06:31.920
and this goes into a lot more details on each of those points.

91
06:31.920 --> 06:39.150
For example, what should the prompt print in the beginning of the program, and then how to turn the

92
06:39.150 --> 06:46.930
machine off, how to print the report, and how each of those points should work in detail.

93
06:46.960 --> 06:53.470
Go ahead and download this and make sure you read each of the sections and test it out in the final

94
06:53.470 --> 06:55.900
working version of the project.

95
06:56.620 --> 07:02.920
Once you're ready, you can go ahead and head over to the starting version of the code, and I want

96
07:02.920 --> 07:08.440
you to create a new project using PyCharm and call it CoffeeMachine.

97
07:10.990 --> 07:21.050
And then create a new file inside your project called main.py, and then paste all of the starting code

98
07:21.050 --> 07:23.180
into your main.py.

99
07:23.180 --> 07:26.120
And now you're going to code inside this file.

100
07:26.120 --> 07:29.210
And once you're ready, you're going to click Run,

101
07:29.210 --> 07:32.750
and you'll be able to run this main.py down here,

102
07:32.750 --> 07:34.970
and this will act as your console.

103
07:35.570 --> 07:41.360
So if I go ahead and take some of these program requirements, I can put them in as TODOs.

104
07:41.360 --> 07:44.810
To create a TODO you have to follow the syntax.

105
07:44.810 --> 07:47.660
First is a pound sign #,

106
07:47.660 --> 07:50.900
and then we write TODO in all caps.

107
07:50.900 --> 07:53.930
And notice how that's just changed color just now.

108
07:53.930 --> 07:58.640
And now you can see in the TODO tab it's found one TODO item.

109
07:58.820 --> 08:02.910
Now we can write TODO Number 1,

110
08:02.910 --> 08:07.920
and this is to print a report of all the coffee machine resources.

111
08:08.550 --> 08:12.420
Now let's say that I created a TODO somewhere else,

112
08:12.420 --> 08:12.750
right?

113
08:12.750 --> 08:14.640
Like all the way up here.

114
08:15.270 --> 08:20.310
"Check that the resources are sufficient to make the drink order."

115
08:20.370 --> 08:24.420
And notice how they're completely in different places, in a different order,

116
08:24.420 --> 08:30.490
but every time I create one of these TODOs using this format, it will get picked up in the TODO tab

117
08:30.490 --> 08:33.370
and you can go ahead and see where they live.

118
08:33.370 --> 08:37.240
So it's found two items inside our main.py.

119
08:37.240 --> 08:39.910
And you can see that this one is TODO: 1.

120
08:39.910 --> 08:41.260
This one is TODO: 2.

121
08:41.260 --> 08:45.460
And when you click on them they'll take you to the correct places in your code.

122
08:46.120 --> 08:52.750
Use this to break down the problem into smaller problems that you can solve one by one, just as you've

123
08:52.750 --> 08:56.890
done before, and try to see if you can complete this project.

124
08:56.920 --> 08:58.480
Just a word of warning.

125
08:58.480 --> 09:04.960
This project is quite ambitious, so give this problem at least an hour to work on it and make sure

126
09:04.960 --> 09:11.890
that you satisfy all the criteria that's set out in the program requirements, and also that your program

127
09:11.890 --> 09:17.260
works exactly the same as the final version of the Coffee Machine.