Elika in High School Elika in College Elika

  • Slides: 54
Download presentation

Eliška in High School

Eliška in High School

Eliška in College

Eliška in College

Eliška teaching

Eliška teaching

Ondra

Ondra

Control Statements for(int i = 0; i < N; i++) { // to repeat

Control Statements for(int i = 0; i < N; i++) { // to repeat N times } while(condition) { // repeat while condition holds } if(condition) { // todo if true } else { // todo if false }

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add.

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add. Leaves. To. Tree(); } move. To. Wall(); } private void add. Leaves. To. Tree() { turn. Left(); climb. Tree(); add. Leaves(); descend. To. Ground(); turn. Left(); private void find. Tree() { move. To. Wall(); }

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add.

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add. Leaves. To. Tree(); } move. To. Wall(); } private void add. Leaves. To. Tree() { turn. Left(); climb. Tree(); add. Leaves(); descend. To. Ground(); turn. Left(); private void find. Tree() { move. To. Wall(); }

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add.

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add. Leaves. To. Tree(); } move. To. Wall(); } private void add. Leaves. To. Tree() { turn. Left(); climb. Tree(); add. Leaves(); descend. To. Ground(); turn. Left(); private void find. Tree() { move. To. Wall(); }

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add.

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add. Leaves. To. Tree(); } move. To. Wall(); } private void add. Leaves. To. Tree() { turn. Left(); climb. Tree(); add. Leaves(); descend. To. Ground(); turn. Left(); } private void find. Tree() { move. To. Wall(); }

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add.

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add. Leaves. To. Tree(); } move. To. Wall(); } private void add. Leaves. To. Tree() { turn. Left(); climb. Tree(); add. Leaves(); descend. To. Ground(); turn. Left(); } private void find. Tree() { move. To. Wall(); }

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add.

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add. Leaves. To. Tree(); } move. To. Wall(); } private void add. Leaves. To. Tree() { turn. Left(); climb. Tree(); add. Leaves(); descend. To. Ground(); turn. Left(); } private void find. Tree() { move. To. Wall(); }

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add.

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add. Leaves. To. Tree(); } move. To. Wall(); } private void add. Leaves. To. Tree() { turn. Left(); climb. Tree(); add. Leaves(); descend. To. Ground(); turn. Left(); } private void find. Tree() { move. To. Wall(); }

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add.

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add. Leaves. To. Tree(); } move. To. Wall(); } private void add. Leaves. To. Tree() { turn. Left(); climb. Tree(); add. Leaves(); descend. To. Ground(); turn. Left(); } private void find. Tree() { move. To. Wall(); }

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add.

Readable code public void run() { while (beepers. In. Bag()) { find. Tree(); add. Leaves. To. Tree(); } move. To. Wall(); } private void add. Leaves. To. Tree() { turn. Left(); climb. Tree(); add. Leaves(); descend. To. Ground(); turn. Left(); } private void find. Tree() { move. To. Wall(); }

Decomposition

Decomposition

Decomposition public void run() { move(); turn. Left(); move(); pick. Beeper(); turn. Left(); move();

Decomposition public void run() { move(); turn. Left(); move(); pick. Beeper(); turn. Left(); move(); turn. Left(); move(); }

Decomposition Collect Newspaper = Exit House then Pick. Up. Paper then Return. Home

Decomposition Collect Newspaper = Exit House then Pick. Up. Paper then Return. Home

Decomposition public void run() { exit. House(); pick. Up. Paper() ; return. Home(); }

Decomposition public void run() { exit. House(); pick. Up. Paper() ; return. Home(); } private void exit. House() { move(); turn. Right(); move(); turn. Left(); move(); } private void pick. Up. Paper() { pick. Beeper(); } private void return. Home() { turn. Around(); move(); turn. Right(); move(); }

Method names private void best. Method. Ever() {. . . } private void best.

Method names private void best. Method. Ever() {. . . } private void best. Method. Ever. Better() {. . . }

Method names private void turn. Right() {. . . } private void build. Column()

Method names private void turn. Right() {. . . } private void build. Column() {. . . }

See You Later! I will miss you. Enjoy Java! Call me maybe?

See You Later! I will miss you. Enjoy Java! Call me maybe?

Java

Java

Our TO DO list How to write a console program? What are variables? How

Our TO DO list How to write a console program? What are variables? How to get user input in a console program? How to use variables?

Console Program Do you like trains? Yes

Console Program Do you like trains? Yes

Hello World import acm. program. *; public class Hello. Program extends Console. Program {

Hello World import acm. program. *; public class Hello. Program extends Console. Program { public void run() { println("Hello world!"); } } Hello. Console Hello world!

Our TO DO list How to write a console program? What are variables? How

Our TO DO list How to write a console program? What are variables? How to get user input in a console program? How to use variables?

What is a variable?

What is a variable?

Variables in maths 2 x + 3 x - 4 y = 0

Variables in maths 2 x + 3 x - 4 y = 0

Variables in computer science

Variables in computer science

Declaring a variable

Declaring a variable

Declaring a variable - TYPE int

Declaring a variable - TYPE int

Declaring a variable - NAME int counter c n u o r e t

Declaring a variable - NAME int counter c n u o r e t

Declaring a variable - VALUE int counter = 42; 42 c n u o

Declaring a variable - VALUE int counter = 42; 42 c n u o r e t

Variable types 42. 38 ‘a’ 42 true “ ” o l hel

Variable types 42. 38 ‘a’ 42 true “ ” o l hel

Variable types in Java String str = “Hi”; int num = 5; double fraction

Variable types in Java String str = “Hi”; int num = 5; double fraction = 0. 2; boolean cond = false; char cond = ‘X’;

How heavy are you?

How heavy are you?

How Many Children Do I Have?

How Many Children Do I Have?

Our TO DO list How to write a console program? What are variables? How

Our TO DO list How to write a console program? What are variables? How to get user input in a console program? How to use variables?

User Input int children = read. Int(“message”); double weight = read. Double(“message”); String name

User Input int children = read. Int(“message”); double weight = read. Double(“message”); String name = read. Line(“message”);

Our TO DO list How to write a console program? What are variables? How

Our TO DO list How to write a console program? What are variables? How to get user input in a console program? How to use variables?

Binary Operators + Addition – Subtraction * Multiplication / Division % Remainde r

Binary Operators + Addition – Subtraction * Multiplication / Division % Remainde r

PROGRAMMI NG

PROGRAMMI NG

What do you think this does? import acm. program. *; public class Hello. Program

What do you think this does? import acm. program. *; public class Hello. Program extends Console. Program { public void run() { println(1/2); } }

Resulting Type int / int = int double / double = double int /

Resulting Type int / int = int double / double = double int / double = double

PROGRAMMI NG

PROGRAMMI NG

Comparison Operators < Less Than > Greater Than <= Less or Equal >= More

Comparison Operators < Less Than > Greater Than <= Less or Equal >= More or Equal == Equal To != Not Equal To

PROGRAMMI NG

PROGRAMMI NG

Our TO DO list How to write a console program? What are variables? How

Our TO DO list How to write a console program? What are variables? How to get user input in a console program? How to use variables?

Your job: Play with variables!

Your job: Play with variables!