CSBridge Darafaka Lisesi. 2014 Boazii nv. 2015 Ko nv. 2016 Ko - PowerPoint PPT Presentation
CSBridge Darafaka Lisesi. 2014 Boazii nv. 2015 Ko nv. 2016 Ko nv. 2017 CTU, Czech Republic + Ko nv. 2018 Bryce Julia Asena Nick Chris Ou Our awesome 2019 2019 Ko Ko te teaching te team! Bar Pelin
CSBridge
Darüşşafaka Lisesi. 2014 Boğaziçi Ünv. 2015 Koç Ünv. 2016 Koç Ünv. 2017 CTU, Czech Republic + Koç Ünv. 2018
Bryce Julia Asena Nick Chris
Ou Our awesome 2019 2019 Ko Koç te teaching te team!
Barış Pelin
Logistics (computer) LOL: Lots of Labs! Labrador Retrievers (Labs)
Logistics Discussion Section Meet your friends and talk through problems with your Section Leader!
Stanford?
Stanford
Prerequisites
Course Website http://koc.csbridge.org *note that its or org , not co com
Very High Level Journey
Breakout
What if I fall behind? CS Bridge
Share Ideas Not Code
Questions?
Our First Step
Karel
Karel Speaks Java s
Karel’s World North 3 + + + + + West East + + + + + 2 1 + + + + + South 1 2 3 4 5
Walls 3 + + + + 2 + + + + 1 + + + + 1 2 3 4
Beepers 3 + + + + 2 + + + + 1 + + + + 1 2 3 4
Knows Four Commands move(); turnLeft(); pickBeeper(); putBeeper();
move();
move(); 3 + + + + 2 + + + + 1 + + + + 1 2 3 4
move(); 3 + + + + 2 + + + + 1 + + + + + 1 2 3 4
turnLeft();
turnLeft(); 3 + + + + 2 + + + + 1 + + + + + 1 2 3 4
turnLeft(); 3 + + + + 2 + + + + 1 + + + + + 1 2 3 4
pickBeeper();
pickBeeper(); 3 + + + + 2 + + + + 1 + + + + + 1 2 3 4
pickBeeper(); 3 + + + + 2 + + + + 1 + + + + + 1 2 3 4
putBeeper();
putBeeper(); 3 + + + + 2 + + + + 1 + + + + + 1 2 3 4
putBeeper(); 3 + + + + 2 + + + + 1 + + + + + 1 2 3 4
Questions?
First Challenge 3 + + + + 2 + + + + 1 + + + + 1 2 3 4
First Challenge 3 + + + + 2 + + + + 1 + + + + 1 2 3 4
First Challenge move(); pickBeeper(); turnLeft(); putBeeper();
Need a Volunteer
First Challenge move(); pickBeeper(); turnLeft(); putBeeper();
Let’s Try It StepUp.java
Questions?
Improving our Program import stanford.karel.*; public class StepUp extends Karel { public void run() { move(); pickBeeper(); turnLeft(); It’s “Turn Right”, but… move(); 🙂 not very clear turnLeft(); turnLeft(); 😪 tedious turnLeft(); move(); putBeeper(); move(); } }
Improving our Program import stanford.karel.*; public class StepUp extends Karel { public void run() { move(); pickBeeper(); turnLeft(); move(); // turns Karel right turnLeft(); turnLeft(); turnLeft(); move(); It’s “Turn Right”, but… putBeeper(); move(); descriptive comments } 😪 tedious }
Anatomy of a Program import stanford.karel.*; public class StepUp extends Karel { public void run() { move(); pickBeeper(); turnLeft(); move(); This is the // turns Karel right program's turnLeft(); sour so urce e code de turnLeft(); turnLeft(); move(); putBeeper(); move(); } }
Anatomy of a Program import stanford.karel.*; public class StepUp extends Karel { public void run() { move(); pickBeeper(); turnLeft(); move(); This piece of the // turns Karel right turnLeft(); program’s so sour urce e code de is turnLeft(); called a me method . turnLeft(); move(); putBeeper(); move(); } }
Anatomy of a Program import stanford.karel.*; public class StepUp extends Karel { public void run() { name of This word is the nam move(); pickBeeper(); method (here, run) our me turnLeft(); move(); // turns Karel right turnLeft(); turnLeft(); We must always have a run() turnLeft(); method to run our program. move(); putBeeper(); move(); But we can make an any } oth other er m meth thod ods w s we w e want ! }
Method Definition private void name () { statements in the method body } w e n a s s d ’ l e d r a a s K i h o T t d n a y m r a m l u o b c a c o v
Improving our Program import stanford.karel.*; public class StepUp extends Karel { public void run() { move(); pickBeeper(); turnLeft(); Call our turnRight me Ca method move(); turnRight(); move(); putBeeper(); move(); } private void turnRight() { turnLeft(); Define a turnRight turnLeft(); me method turnLeft(); } }
Anatomy of a Program import stanford.karel.*; public class StepUp extends Karel { public void run() { move(); pickBeeper(); turnLeft(); move(); This is called an turnRight(); import statement . im move(); putBeeper(); It tells Java what Karel is. move(); } private void turnRight() { turnLeft(); turnLeft(); turnLeft(); } }
Anatomy of a Program import stanford.karel.*; public class StepUp extends Karel { public void run() { move(); pickBeeper(); turnLeft(); move(); turnRight(); This is called a move(); co code block . putBeeper(); move(); } private void turnRight() { turnLeft(); turnLeft(); turnLeft(); } }
Program Style import stanford.karel.*; public class StepUp extends Karel { public void run() { move(); pickBeeper(); These are turnLeft(); terrifying! move(); turnRight(); move(); putBeeper(); move(); } private void turnRight() { turnLeft(); turnLeft(); turnLeft(); } }
Program Style import stanford.karel.*; public class StepUp extends Karel { public void run() { move(); pickBeeper(); Style Ti St Tip #1 : turnLeft(); Align braces in move(); turnRight(); your code blocks. move(); putBeeper(); move(); } private void turnRight() { turnLeft(); turnLeft(); turnLeft(); } }
Program Style import stanford.karel.*; public class StepUp extends Karel { public void run() { move(); pickBeeper(); Style Ti St Tip #1 : turnLeft(); Align braces in move(); turnRight(); your code blocks. move(); putBeeper(); move(); } private void turnRight() { turnLeft(); turnLeft(); turnLeft(); } }
Program Style import stanford.karel.*; public class StepUp extends Karel { public void run() { move(); pickBeeper(); Style Ti St Tip #1 : turnLeft(); Align braces in move(); turnRight(); your code blocks. move(); putBeeper(); move(); } private void turnRight() { turnLeft(); turnLeft(); turnLeft(); } }
Program Style import stanford.karel.*; public class StepUp extends Karel { public void run() { move(); pickBeeper(); turnLeft(); move(); Style Ti St Tip #2 : turnRight(); move(); Align indentation putBeeper(); in your code blocks. move(); } private void turnRight() { turnLeft(); turnLeft(); turnLeft(); } }
Program Style import stanford.karel.*; public class StepUp extends Karel { public void run() { move(); pickBeeper(); turnLeft(); move(); Style Ti St Tip #2 : turnRight(); move(); Align indentation putBeeper(); in your code blocks. move(); } private void turnRight() { turnLeft(); turnLeft(); turnLeft(); } }
Questions?
Place 100 beeper? Place100.java
For Loop for (int i = 0; i < N ; i++) { // to repeat N times }
Review Helper me ds for defining new commands metho thods private void name () { statements in the method body } for loops repeat code N times fo N for (int i = 0; i < N ; i++) { // to repeat N times }
Today’s Examples on the Website
Today’s Slides on the Website
Your turn x 200 (in Labs)
Newspaper Karel
Your turn To the Labs!!
Build Efes
Recommend
More recommend
Explore More Topics
Stay informed with curated content and fresh updates.