/
class1.html
1008 lines (917 loc) · 29.9 KB
/
class1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GDI Introduction to C# and OOP Concepts</title>
<meta name="description" content="Intro to Object Oriented Programming with C# curriculum was
developed by Paige Bystrom for Girl Develop It. The course is meant to be taught in 4 2-hour sections.
The slides are customizable according to the needs of a given class or audience.">
<meta name="author" content="Ashley Price">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="icon" href="reveal/favicon.ico">
<link rel="stylesheet" href="reveal/css/reveal.css">
<link rel="stylesheet" href="reveal/css/theme/gdisunny.css" id="theme">
<link rel="stylesheet" href="css/gdi.css">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="reveal/lib/css/zenburn.css">
<!-- For the slides -->
<link rel="stylesheet" href="css/slides.css">
<!-- If use the PDF print sheet so students can print slides-->
<link rel="stylesheet" href="reveal/css/print/pdf.css" type="text/css" media="print">
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<!-- Opening slide -->
<section class='title-page'>
<img src="images/watermark-logo-2.png" alt="" />
<h3>Intro to C# and OOP Concepts</h3>
<h4>Class 1</h4>
<h5>Developed for GDI by Paige Bystrom and Ashley Price</h5>
</section>
<!-- Welcome-->
<section>
<h3>Welcome!</h3>
<p>Girl Develop It is here to provide affordable and accessible programs to learn software
through mentorship and hands-on instruction.</p>
<h3>Some "Rules"</h3>
<ul>
<li>We are here for you!</li>
<li>Every question is important</li>
<li>Help each other</li>
<li>Be Respectful</li>
<li>Have fun!</li>
</ul>
</section>
<!-- Introductions: Instructor & TAs -->
<section>
<h3>Who are we?</h3>
<div class="bio-card bio-card-3">
<h4>Instructor:</h4>
<p>Paige Bystrom</p>
<img class="thumbnail paige-intro"/>
<a href="https://twitter.com/radmint/" class="caption">@radmint</a>
</div>
<div class="bio-card bio-card-3">
<h4>TA:</h4>
<p>Name</p>
<img class="thumbnail"/>
<a class="caption">@twitter-handle</a>
</div>
<div class="bio-card bio-card-3">
<h4>TA:</h4>
<p>Name</p>
<img class="thumbnail"/>
<a class="caption">@twitter-handle</a>
</div>
</section>
<!-- Course Agenda: Class 1 -->
<section>
<h3>Course agenda</h3>
<h4>Class 1:</h4>
<ul>
<li>Creating a new C# Solution</li>
<li>Variables</li>
<li>Operators</li>
<li>Expressions</li>
<li>Statements</li>
<li>Flow Control</li>
<li>Objects</li>
<li>Methods</li>
<li>Constructors</li>
</ul>
</section>
<!-- Course Agenda: Class 2 -->
<section>
<h3>Course agenda</h3>
<h4>Class 2:</h4>
<ul>
<li></li>
</ul>
</section>
<!-- Course Agenda: Class 3 -->
<section>
<h3>Course agenda</h3>
<h4>Class 3:</h4>
<ul>
<li></li>
</ul>
</section>
<!-- Course Agenda: Class 4 -->
<section>
<h3>Course agenda</h3>
<h4>Class 4:</h4>
<ul>
<li></li>
</ul>
</section>
<!-- Introductions: Attendees -->
<section>
<h3>Introductions</h3>
<ul>
<li>Who are you?</li>
<li>What spurred you into learning about development?</li>
<li>What do you hope to get out of the class?</li>
<li>What's your favorite pasttime?</li>
</ul>
</section>
<!-- Creating a new project -->
<section>
<h3>Creating a new C# Project</h3>
<ol>
<li>
Open Visual Studio
</li>
<li>
Navigate to File
</li>
<li>
New Solution
</li>
<li>.NET Core > App > Console Application</li>
</ol>
</section>
<!-- Default Main method -->
<section>
<h3>Default Main Method</h3>
<p>In C#, every application contains a main method that acts as an entry point for the
application</p>
<pre><code class="java">
using System;
namespace Pizzeria
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
</code></pre>
</section>
<!-- Default Main method cont. -->
<section>
<h3>Default Main Method (cont.)</h3>
<pre><code class="java">
using System;
namespace Pizzeria
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
</code></pre>
<ol class="question-list">
<li>What happens if we remove the <code>using System;</code> statement?</li>
<li>What happens if we change the name of the class <code>Program</code>?</li>
<li>What happens if we change the name of the <code>Main()</code> method?</li>
<li>What happens if we remove the <code>string[] args</code> argument?</li>
</ol>
</section>
<!-- Variables -->
<section>
<h3>Variables</h3>
<p>What are variables?</p>
<p>C# is a statically typed language with type inference</p>
<p>You must declare all variables before you use them. The declaration must include the
variable type and the variable name.</p>
</section>
<!-- Primitive Variables -->
<section>
<h3>Primitive Variables</h3>
<p>A primitive variable is the most basic type of value in a language.</p>
<p>Primitive types we'll be looking at include: </p>
<ul>
<li><code>int</code></li>
<li><code>double</code></li>
<li><code>bool</code></li>
</ul>
</section>
<!-- Creating Variables: Develop it -->
<section>
<h3>Develop It: Creating Variables</h3>
<p>Declare a variable with the following format: </p>
<pre><code class='java'>type name;</code></pre>
<p>We're going to create the following variables: </p>
<ul>
<li><code>int numberOfPizzas</code></li>
<li><code>int maxNumberOfPizzas</code></li>
<li><code>bool isOrderFull</code></li>
<li><code>double orderCost</code></li>
</ul>
</section>
<!-- Creating Variables: Solution -->
<section>
<h3>The Code</h3>
<pre><code class='java'>
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
int numberOfPizzas;
int maxNumberOfPizzas;
bool isOrderFull;
double orderCost;
}
</code></pre>
</section>
<!-- Statically types variables -->
<section>
<h3>Statically Typed Variables Illustrated</h3>
<p>You can think of variables as boxes that hold a value</p>
<p>In statically typed languages, variables only hold the type of value they were
declared to: </p>
<img src="images/variables_illustrated.png">
</section>
<!-- Operators overview -->
<section>
<h3>Operators</h3>
<ul>
<li>Assignment</li>
<li>Arithmetic</li>
<li>Equality and Relationship</li>
<li>Conditional</li>
<li>Precedence</li>
</ul>
</section>
<!-- Assignment operators -->
<section>
<h3>Assignment Operators</h3>
<p>To assign a value to a variable we use the assignment operator: </p>
<pre><code class='java'>=</code></pre>
<p>Let's try it out: </p>
<pre><code class='java'>numberOfPizzas = 1;</code></pre>
</section>
<!-- Variable initialization -->
<section>
<h3>Variable Initialization</h3>
<p>We just <em>initialized</em> <code>numberOfPizzas</code></p>
<p>Initilization is the first (initial) assignment of a value to a variable</p>
<p>You should always initialize your variables before using them in your program</p>
<p>You can initialize your variables when you declare them: </p>
<pre><code class='java'>int maxNumberPizzas = 2</code></pre>
</section>
<!-- Variable initialization: Develop it -->
<section>
<h3>Develop it!</h3>
<p><code>bool</code> variables can have one of two possible values:</p>
<ul>
<li>true</li>
<li>false</li>
</ul>
<p><span class='individually'>On your own,</span> initialize the variable
<code>isOrderFull</code> with the value <code>false</code></p>
</section>
<!-- Variable initialization: Solution -->
<section>
<h3>The Code:</h3>
<pre><code class='java'>
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
int numberOfPizzas;
int maxNumberOfPizzas = 2;
bool isOrderFull = false;
numberOfPizzas = 1;
}
</code></pre>
</section>
<!-- Arithmetic Operators -->
<section>
<h3>Arithmetic Operators</h3>
<p>We can have arithmetic operators in programming that are much like what we learned in
math class:</p>
<pre><code class='java'>+, -, *, /</code></pre>
<p>Add, subtract, multiply and divide</p>
</section>
<!-- Arithmetic Operators: Develop it -->
<section>
<h3>Develop It!</h3>
<pre><code class='java'>
maxNumberOfPizzas = maxNumberOfPizzas + 3;
//we've increased our delivery capacity!
</code></pre>
</section>
<!-- Arithmetic Operators: Develop it -->
<section>
<h3>Develop it!</h3>
<p class='individually'>On your own: </p>
<ul>
<li>Increment the <code>numberOfPizzas</code> value by one</li>
<li>Then use the <code>Console.WriteLine()</code> method to show the result:
<pre><code class='java'>
Console.WriteLine("Number of Pizzas: " + numberOfPizzas);
</code></pre>
</li>
</ul>
</section>
<!-- Arithmetic Operators: Solution -->
<section>
<h3>The Code</h3>
<pre><code class='java'>
numberOfPizzas = numberOfPizzas + 3;
Console.WriteLine("Number of Pizzas: " + numberOfPizzas);
</code></pre>
<p>You can write this in shorthand using the ++ operator: </p>
<pre><code class='java'>
numberOfPizzas++;
</code></pre>
<p>Output: </p>
<pre><code class='no-highlight'>
Hello World
Number of Pizzas: 2
</code></pre>
</section>
<!-- Arithmetic Operators: Develop it -->
<section>
<h3>Develop It: Playing with Arithmetic Operators</h3>
<p><span class='individually'>On your own:</span></p>
<ol>
<li>Create an integer called <code>orderCost</code></li>
<li>Initialize it with the value 0</li>
<li>Increase the value by 13</li>
<li>Print the new order cost</li>
<li>Now reduce the order cost by half</li>
<li>Print the new order cost</li>
</ol>
</section>
<!-- Arithmetic Operators: Expected output -->
<section>
<h3>Expected Output: </h3>
<pre><code class='no-highlight'>
Hello World!
Number of Pizzas: 2
Cost of the order is: 13
Cost of the order is: 6
</code></pre>
<p>But <em>is</em> this what we would expect?</p>
<p>Try changing the <em>type</em> of orderCost to <code>double</code></p>
<p>What happens when we run the solution now?</p>
</section>
<!-- Arithmetic Operators: Solution -->
<section>
<h3>The Code</h3>
<pre><code class='java'>
double orderCost = 0;
orderCost = orderCost + 13;
Console.WriteLine("Cost of the order is: " + orderCost);
orderCost = orderCost / 2;
Console.WriteLine("Cost of the order is: " + orderCost);
</code></pre>
</section>
<!-- Equality and relationship operators -->
<section>
<h3>Equality and Relationship Operators</h3>
<p>These operators evaluate to <code>true</code> or <code>false:</code></p>
<table>
<tr>
<td><code>==</code></td><td>Equal</td>
</tr>
<tr>
<td><code>!=</code></td><td>Not Equal</td>
</tr>
<tr>
<td><code><</code></td><td>Less than</td>
</tr>
<tr>
<td><code>></code></td><td>Greater than</td>
</tr>
<tr>
<td><code><=</code></td><td>Less than or Equal to</td>
</tr>
<tr>
<td><code>>=</code></td><td>Greater than or Equal to</td>
</tr>
</table>
</section>
<!-- Equality and relationship operators: Develop it -->
<section>
<h3>Develop it!</h3>
<pre><code class='java'>
isOrderFull = (numberOfPizzas == maxNumberOfPizzas);
Console.WriteLine("The order is full: " + isOrderFull);
</code></pre>
<p>Output:</p>
<pre><code class='no-highlight'>
The order is full: false
</code></pre>
</section>
<!-- Equality and relationship operators: Develop it -->
<section>
<h3>Develop It - <span class='individually'>Individually</span></h3>
<ol>
<li>In a boolean <code>hasSpace</code>, assign the resulting value of the question
"Is our number of pizzas less than our max number of pizzas?"</li>
<li>Print the result</li>
<li>Test if the <code>numberOfPizzas</code> is greater than or equal to
<code>maxNumberOfPizzas</code> and store it in <code>isOrderFull</code></li>
<li>Print the result</li>
</ol>
</section>
<!-- Equality and relationship operators: Solution -->
<section>
<h3>Example Answer</h3>
<pre><code class='java'>
hasSpace = numberOfPizzas < maxNumberOfPizzas;
Console.Write("We have less than the number of max pizzas: " + hasSpace);
bool isOrderFull = numberOfPizzas > maxNumberOfPizzas;
Console.Write("I'm full! " + isOrderFull);
</code></pre>
<p>Output:</p>
<pre><code class='no-highlight'>
We have less than the number of max pizzas: True
I'm full! False
</code></pre>
</section>
<!-- Conditional operators -->
<section>
<h3>Conditional Operators</h3>
<table>
<tr>
<td>&&</td><td>And (short-circuit)</td>
</tr>
<tr>
<td>&</td><td>And</td>
</tr>
<tr>
<td>||</td><td>Or (short-circuit)</td>
</tr>
<tr>
<td>|</td><td>Or</td>
</tr>
</table>
<p>We can check if two values are true</p>
<pre><code class='java'>
bool isEmptyOrder = orderCost <= 0 && numberOfPizzas <= 0;
</code></pre>
</section>
<!-- Conditional operators: Develop it -->
<section>
<h3>Develop It!</h3>
<p>Create a <code>bool</code> called <code>isLargeOrder</code> that evaluates to
<code>true</code> if the order is full or if the order cost is greater than
or equal to $50.</code></p>
</section>
<!-- Conditional operators: Solution -->
<section>
<h3>The Code</h3>
<pre><code class='java'>
bool isLargeOrder = isOrderFull || orderCost >= 50;
Console.WriteLine("Alert! Large order incoming: " + isLargeOrder);
</code></pre>
</section>
<!-- Precedence -->
<section>
<h3>Precedence</h3>
<p>Remember PEMDAS in math class? We have to keep in mind that multiplication and division
happen before addition and subtraction. All operators have an order of precedence.
Check out the
<a href="https://docs.microsoft.com/en-us/dotnet/java/language-reference/operators/"
target="_blank">Official Documentation</a></p>
</section>
<!-- Precedence -->
<section>
<h3>Precedence</h3>
<p>Our previous example: </p>
<pre><code class='java'>bool isEmptyOrder = orderCost <= 0 && numberOfPizzas
<= 0</code></pre>
<p>According to the precedence chart evaluates:</p>
<table>
<tr>
<td><code>orderCost <= 0,</br> numberOfPizzas <= 0</code></td>
<td>relational</td>
</tr>
<tr>
<td><code>&&</code></td><td>logical and</td>
</tr>
<tr>
<td><code>=</code></td><td>assignment</td>
</tr>
</table>
</section>
</section>
<!-- Expressions -->
<section>
<h3>Expressions</h3>
<p>An expression is a piece of code that evaluates to a value.</p>
<p>Example:</p>
<pre><code class='java'>
numberOfPizzas < maxNumberOfPizzas
</code></pre>
<p>This expression could be <code>true</code> or <code>false</code> depending on the values
of the variables, but it is not a complete statement of execution</p>
</section>
<!-- Statement -->
<section>
<h3>Statement</h3>
<p>A statement is a complete unit of execution. It's a sentence in the C# Language. An
instruction that can be carried out from start to end.</p>
<p>Let's take a look at one of the statements we've written:</p>
<pre><code class='java'>
bool isEmptyOrder = orderCost <= 0 && numberOfPizzas <= 0;
</code></pre>
</section>
<!-- Checkpoint -->
<section>
<h3>Checkpoint</h3>
<p>Reviewing Variables & Operators</p>
</section>
<!-- Flow Control -->
<section>
<h3>Flow Control</h3>
<p>In our example program, each statement is executed one after another.</p>
<p>What if we wanted to make a choice about whether or not a statement was executed?</p>
<p>If the number of pizzas is less than the max allowed, tell a customer they can add a
pizza to their order. Otherwise, tell them they've reached their max.</p>
</section>
<!-- Conditional -->
<section>
<h3>Conditional If/Else</h3>
<p>The If/Else statement used with an expression that evaluates to a bool, allows us to
make choices</p>
<pre><code class='java'>
if (orderCost == 0) {
Console.Write("Customer has not yet ordered");
} else {
Console.Write("Customer has placed an order!");
}
</code></pre>
</section>
<!-- Conditional: Develop it -->
<section>
<h3>Develop it!</h3>
<p>If the number of pizzas is less than the max number of pizzas allowed, tell the customer
they can add a pizza to their order</p>
<p>Otherwise, tell them they've reached their max number of pizzas.</p>
</section>
<!-- Conditional: Solution -->
<section>
<h3>The Code</h3>
<pre><code class='java'>
if (numberOfPizzas < maxNumberOfPizzas) {
Console.Write("You can add a pizza to your order!");
} else {
Console.Write("You can't order any more pizza");
}
</code></pre>
<p>Output: </p>
<pre><code class='no-highlight'>
You can add a pizza to your order!
</code></pre>
</section>
<!-- Conditional Else if -->
<section>
<h3>Else if</h3>
<p>You also have an <code>else if</code> statement at your disposal:</p>
<pre><code class='java'>
if (orderCost == 0) {
Console.Write("Customer has not yet ordered");
} else if (orderCost >= 50) {
Console.Write("Alert! Large order incoming!");
} else {
Console.Write("Customer has placed an order!");
}
</code></pre>
</section>
<!-- Conditional Else if: Develop It -->
<section>
<h3>Develop it - <span class='individually'>Individually</span></h3>
<p>Add an <code>else if</code> statement to your current if/else block that prints out
"You can order one more pizza" if the number of pizzas is equal to the number of
max pizas minus 1.</p>
</section>
<!-- Conditional Else if: Solution -->
<section>
<h3>The Code</h3>
<pre><code class='java'>
if (numberOfPizzas < maxNumberOfPizzas) {
Console.Write("You can add a pizza to your order!");
} else if (numberOfPizzas == maxNumberOfPizzas - 1) {
Console.Write("You can order one more pizza");
} else {
Console.Write("You can't order any more pizza");
}
</code></pre>
</section>
<!-- Switch statement -->
<section>
<h3>Switch Statement</h3>
<p>A switch statement evaluates the value of an integer or string and executes all
the statements following the matching "case" block.</p>
<p>In other words, it evaluates the conditional once and starts execution from there
until it is told to stop or hits the end of the block</p>
<pre><code class='java'>switch (deliveryTimeInHours) {
case 1:
Console.Write("Your pizza will arrive in 1 hour");
break;
case 2:
Console.Write("We're busy! Your pizza will arrive 2 hours");
break;
default:
Console.Write("Delivery time unknown");
break;
}</code></pre>
</section>
<!-- Switch statement: Develop it -->
<section>
<h3>Develop It!</h3>
<p>Let's create a <code>switch</code> statement based on the <code>numberOfPizzas</code> variable</p>
<p>Print the following sayings for the corresponding value: </p>
<ol start="0">
<li>You haven't added a pizza to your order</li>
<li>Dinner for one?</li>
<li>Having a couple of guests over?</li>
<li>You've reached the pizza limit!</li>
</ol>
<p>Default: Pizza time!</p>
</section>
<!-- Switch statement: Breaks -->
<section>
<h3>Wait a Minute! Take a break</h3>
<p>Without any <code>break</code> statements, the <code>switch</code> blocks "falls through" and
executes everything after the matching value too!</p>
</section>
<!-- Switch statement: Solution -->
<section>
<h3>The Code</h3>
<pre><code class='java'>
switch (numberOfPizzas) {
case 0:
Console.Write("You haven't added a pizza to your order");
break;
case 1:
Console.Write("Dinner for one?");
break;
case 2:
Console.Write("Having a couple of guests over?");
break;
case maxNumberOfPizzas:
Console.Write("You've reached the pizza limit!");
break;
default:
Console.Write("Pizza time!");
break;
}
</code></pre>
</section>
<!-- Loops -->
<section>
<h3>Loops</h3>
<p>With loops, we can write code once and have it executed multiple times in a row.</p>
</section>
<!-- For loops -->
<section>
<h3>For Loop</h3>
<p>In cases where we know how many times we wish to execute the loop, we can use a
<code>for</code> loop</p>
<p>The <code>for</code> loop structure calls for a variable initialized to a value, the
termination condition, and the increment</p>
<pre><code class='java'>
for (initial variable; test condition; increment) { }
</code></pre>
</section>
<!-- For loops: Develop it-->
<section>
<h3>Develop it!</h3>
<pre><code class='java'>
for (int orderCost = 0; orderCost < 50; orderCost +=10) {
Console.Write("My order costs $" + orderCost + "!");
}
</code></pre>
</section>
<!-- For loops: Solution -->
<section>
<h3>Output</h3>
<pre><code class='no-highlight'>
My order costs $0!
My order costs $10!
My order costs $20!
My order costs $30!
My order costs $40!
</code></pre>
</section>
<!-- While loops -->
<section>
<h3>While Loop</h3>
<p>At other times, we want to execute our code for an unknown number of iterations.
We want to execute it <em>while</em> an expression is true regardless of how many
iterations it takes.</p>
<pre><code class='java'>
while (condition) {
...
}
</code></pre>
</section>
<!-- While loops: Develop it -->
<section>
<h3>Develop It!</h3>
<p>While <code>isOrderFull</code> is true, add a pizza, then update the value of
<code>isOrderFull</code></p>
</section>
<!-- While loops: Solution -->
<section>
<h3>The Code</h3>
<pre><code class='java'>
isOrderFull = numberOfPizzas == maxNumberOfPizzas;
Console.Write("Our max number of pizzas is " + maxNumberOfPizzas);
while (!isOrderFull) {
/* We'll add a pizza */
numberOfPizzas ++;
/* We'll alert how many pizzas we have */
Console.Write("I'm carrying: " + numberOfPizzas);
/* We'll update whether or not we're full */
isOrderFull = numberOfPizzas == maxNumberOfPizzas;
}
</code></pre>
</section>
<!-- Checkpoint -->
<section>
<h3>Checkpoint!</h3>
<p>Flow Control Constructs</p>
</section>
<!-- Intro to Objects -->
<section>
<h3>Part 2: Introduction to Objects</h3>
<p>All real-world obejcts have a <em>state</em> and a <em>behavior</em></p>
<p>We'll use this approach to looking at objects to describe objects in our programming</p>
</br>
<h3>Describing Objects in this room</h3>
<p>Let's take a minute to identify objects in this room and talk about them by identifying their state and behavior</p>
</section>
<!-- Array Objects -->
<section>
<h3>Array Objects</h3>
<ul>
<li>Arrays are containers for values.</li>
<li>Arrays hold a single type of value.</li>
<li>Arrays are a fixed length.</li>
</ul>
</br>
<h3>Real World Array</h3>
<p>7-day pill box - every slot holds a pill</p>
</section>
<!-- Array syntax -->
<section>
<h3>Syntax - Creating an Array</h3>
<pre><code class='java'>
string[] consoles = new string[3];
consoles[0] = "PS4";
consoles[1] = "Xbox";
consoles[2] = "Switch";
</code></pre>
</section>
<!-- Array states -->
<section>
<h3>Array - States</h3>
<p>The state of an array can be described by: </p>
<ul>
<li>How big it is or how many values it can hold (also called its length)</li>
<li>The values it currently holds</li>
</ul>
<p>**Describe our Array in these terms</p>
</section>
<section>
<h3>Arrays and For loops are BFFs</h3>
<pre><code class='java'>
for (int i = 0; i < consoles.Length; i++) {
Console.Write("Console " + i + " is " + consoles[i]);
}
</code></pre>
</section>
<!-- Array states -->
<section>
<h3>String Object</h3>
<p>We've created an array of strings</p>
<p><a href="https://docs.microsoft.com/en-us/dotnet/java/programming-guide/strings/">Strings</a>
are a type of Object</p>
<p>We can create a single string object by declaring a variable of type <code>string</code>
and assigning it a new <code>string</code> object with some value</p>
<pre><code class='java'>
string newConsole = new string("Sega Genesis");
</code></pre>
</section>
<!-- Methods -->
<section>
<h3>Methods</h3>
<p>An object's behavior is defined in its methods.</p>
<p>A method is a block of code that will execute when called upon.</p>
</section>
<!-- String methods -->
<section>
<h3>String Methods</h3>
<p>Some common things that <code>string</code> can do: </p>
<ul>
<li>A <code>string</code> can tell you its length</li>
<li>A <code>string</code> can tell you whether or not it contains a certain value</li>
<li>It can convert itself to lowercase or uppercase</li>
</ul>
</section>
<!-- String methods: Example -->
<section>
<h3>An example in Code</h3>
<pre><code class='java'>
string newConsole = new string("Sega Genesis");
Console.Write("Length: " + newConsole.Length;
Console.Write("Does the word contain 'genesis'?" +
newConsole.Contains("genesis"));
Console.Write("It's all lower " + newConsole.ToLower());
</code></pre>
</section>
<!-- String methods: Develop it -->
<section>
<h3 class='individually'>On your own</h3>
<p>Call and print the result of the <code>ToUpper()</code> method</p>
</section>
<!-- String methods: Solution -->
<section>
<h3>The Code</h3>
<pre><code class='java'>
Console.Write("It's all upper " + newConsole.ToUpper());
</code></pre>
</section>
<!-- Methods cont. -->
<section>
<h3>Methods Continued</h3>
<p>Methods have a return type and a set of parameters</p>
</section>
<!-- Methods return type -->
<section>
<h3>Method Return Types</h3>
<p>Return Type - If the method returns a value, what type is it?</p>
<p>Let's consider the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.string.contains"
target="_blank">Contains()</a> method of a string</p>
<p>Let's consider the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.string.toupper"
target="_blank">ToUpper()</a> method of a string</p>
</section>
<!-- Methods parameters -->
<section>
<h3>Method Parameters</h3>
<p>Parameters- A list of values the methods expects as input when you call on it</p>
<pre><code class='java'>
.Contains("genesis");
</code></pre>
</section>
<!-- Constructors -->
<section>
<h3>Constructors</h3>
<p>When we create an object, its data members have an initial value</p>
<p>The initial state of the object is set by its constructor.</p>
<p>A constructor may take one or more parameters to be used when setting the initial values.</p>
</section>
<!-- Constructors cont. -->
<section>
<h3><code>int</code> -> <code>string</code> & <code>string</code> -> <code>int</code></h3>
<p><code>int</code> can be converted to a <code>string</code> with the
<a href="https://docs.microsoft.com/en-us/dotnet/api/system.int32.tostring"
target="_blank">ToString()</a> method.</p>
<p>Meanwhile, we can get a primitive <code>int</code> value by calling on the
<a href="https://docs.microsoft.com/en-us/dotnet/api/system.int32.parse"
target="_blank">Parse()</a> method.</p>
</section>
<!-- Null -->
<section>
<h3>Null</h3>
<p>A value that represents nothingness <code>null</code> represents no value</p>
<p>If a <code>bool</code> could be yes or no, a <code>null</code> value would signify "undecided"</p>
</section>
</div> <!-- end slides -->
<footer>
<span class='footer-title'>Intro to OOP with C#</span>
<a rel="license" href="http://creativecommons.org/licenses/by-nc/3.0/deed.en_US">
<img alt="Creative Commons License" style="border-width:0"
src="http://i.creativecommons.org/l/by-nc/3.0/80x15.png" /></a>
</footer>
</div> <!-- end reveal -->
<script src="reveal/lib/js/head.min.js"></script>
<script src="reveal/js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'linear', // default/cube/page/concave/zoom/linear/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'reveal/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'reveal/plugin/markdown/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },