presentación 0 - programación básica

54
Basic programming review Christian Rodríguez Bustos Object Oriented Programming Basic programming review

Upload: thekingartur6

Post on 28-Dec-2015

20 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Presentación 0 - Programación Básica

Basic programming review

Christian Rodríguez Bustos

Object Oriented Programming

Basic programming review

Page 2: Presentación 0 - Programación Básica

Basic concepts

Control Structures

Operators Arrays

Agenda

Basic programming review

Page 3: Presentación 0 - Programación Básica

Algorithm

Flow diagram

Speudo code

Basic concepts

Basic programming review

Page 4: Presentación 0 - Programación Básica

Any computing problem can be solved by executing a series of actions in a specific order.

An algorithm is a step-by-step procedure

Basic programming review

Finite Deterministic Precision

Page 5: Presentación 0 - Programación Básica

1. Get out of bed

2. Take off pajamas

3. Take a shower

4. Get dressed

5. Eat breakfast

6. Take the bus

7. Arrive workplace

An algorithm is a step-by-step procedure

Basic programming review

Problem that we want to solve Going to work

Page 6: Presentación 0 - Programación Básica

Algorithms can be represented in several ways

Basic programming review

Algorithm representation

Pseudo Code

Flow diagram/chart

UML activity diagram

Page 7: Presentación 0 - Programación Básica

Informal descriptions or languages help programmers to develop algorithms without having to worry about the strict details of a

programming language syntax.

Pseudo codes are informal descriptions of algorithms

Basic programming review

Set grade counter to one While grade counter is less than or equal to ten

Input the next grade Add the grade into the total

Set the class average to the total divided by ten Print the class average.

All pseudo codes should be: • Human readable • Can easily be converted to any

programming language

I am a pseudo code

Page 8: Presentación 0 - Programación Básica

Flow diagrams are used to represent algorithms

Basic programming review

Begin or End

Process, task, action, or operation

Decision Connector

Input or output

Document

Page connector

Subroutine or function

Resource: What do the different flowchart shapes mean?

Data Storage

Tape

We are used to represent processes flows

Page 9: Presentación 0 - Programación Básica

These Flow diagram and Pseudo code are equivalent

Basic programming review

Page 10: Presentación 0 - Programación Básica

Activities

Decisions

Start (split) or end (join) of concurrent activities

The start (initial state) of the workflow

The end (final state).

Activity diagrams describe the workflow of a system

Basic programming review

Page 11: Presentación 0 - Programación Básica

Activity diagrams describe the workflow of a system

Basic programming review

I am a UML activity diagram

Page 12: Presentación 0 - Programación Básica

Sequence Structure

Selection Statements

Repetition Statements

Control Structures

Page 13: Presentación 0 - Programación Básica

Programs are formed by combining as many sequence, selection and repetition statements.

Control Structures

Basic programming review

selection repetition

if while

if…else do…while

switch for

Page 14: Presentación 0 - Programación Básica

Sequence structure

Basic programming review

An ordered execution of two or more statements are called sequence structure

Page 15: Presentación 0 - Programación Básica

If student’s grade is greater than or equal to 60

Print “Passed”

IF Selection Statement

Basic programming review

Page 16: Presentación 0 - Programación Básica

If student’s grade is greater than or equal to 60

Print “Passed”

Else

Print “Failed”

IF..ELSE Selection Statement

Basic programming review

Page 17: Presentación 0 - Programación Básica

IF..ELSE Selection Statement abbreviated form

Basic programming review

Page 18: Presentación 0 - Programación Básica

If student’s grade is greater than or equal to 90

Print “A”

else

If student’s grade is greater than or equal to 80

Print “B”

else

If student’s grade is greater than or equal to 70

Print “C”

else

If student’s grade is greater than or equal to 60

Print “D”

else

Print “F”

Nested IF..ELSE Selection Statement

Basic programming review

Page 19: Presentación 0 - Programación Básica

Indent both body statements of an

if…else statement.

Do not forget…

Basic programming review

1

Always using braces in an if…else (or other) statement helps prevent their accidental

omission

Page 20: Presentación 0 - Programación Básica

Ugly code is written by ugly people.

Do not be the beast

Basic programming review

I like my code !!

Page 21: Presentación 0 - Programación Básica

Do not worry, we can format the code automatically

Basic programming review

NetBeans Eclipse

Page 22: Presentación 0 - Programación Básica

While product is less or equal than 100 products

Multiply by 3 the number of products

WHILE Repetition Statement

Basic programming review

Be careful with infinite loops!!

Page 23: Presentación 0 - Programación Básica

FOR Repetition Statement

Basic programming review

?????

Page 24: Presentación 0 - Programación Básica

FOR Repetition Statement

Basic programming review

Page 25: Presentación 0 - Programación Básica

FOR Repetition Statement

Basic programming review

Page 26: Presentación 0 - Programación Básica

Vary the control variable from 1 to 100 in increments of 1

Vary the control variable from 100 to 1 in decrements of 1

Vary the control variable from 7 to 77 in increments of 7

Vary the control variable from 20 to 2 in decrements of 2

Vary the control variable over the following sequence of values: ?, ?, ?, ?, ?, ?, ?

Vary the control variable over the following sequence of values: ?, ?, ?, ?, ?,?, ?, ?, ?, ?

FOR Statements header examples

Basic programming review

Page 27: Presentación 0 - Programación Básica

Vary the control variable from 1 to 100 in increments of 1

Vary the control variable from 100 to 1 in decrements of 1

Vary the control variable from 7 to 77 in increments of 7

Vary the control variable from 20 to 2 in decrements of 2

Vary the control variable over the following sequence of values: 2, 5, 8, 11, 14, 17, 20

Vary the control variable over the following sequence of values: 99, 88, 77, 66, 55,44, 33, 22, 11, 0

FOR Statements header examples

Basic programming review

Page 28: Presentación 0 - Programación Básica

FOR Statement example

Basic programming review

Page 29: Presentación 0 - Programación Básica

DO…WHILE Repetition Statement

Basic programming review

Remember always include braces !!!

Page 30: Presentación 0 - Programación Básica

SWITCH Multiple-Selection Statement

Basic programming review

Page 31: Presentación 0 - Programación Básica

SWITCH Multiple-Selection Statement

Basic programming review

Page 32: Presentación 0 - Programación Básica

BREAK and CONTINUE Statements

Basic programming review

Break

Continue

Page 33: Presentación 0 - Programación Básica

Basic programming review

Page 34: Presentación 0 - Programación Básica

Summary

Basic programming review

Page 35: Presentación 0 - Programación Básica

Logical Operators

Assignment Operators

Increment and Decrement Operators

Operators

Page 36: Presentación 0 - Programación Básica

Conditional AND (&&)

Conditional OR (||)

Logical Negation (!)

Logical Operators

Basic programming review

Page 37: Presentación 0 - Programación Básica

Logical Operators - Truth tables

Basic programming review

Page 38: Presentación 0 - Programación Básica

variable = variable operator expression;

Assignment Operators

Basic programming review

Page 39: Presentación 0 - Programación Básica

Compound Assignment Operators

Basic programming review

Page 40: Presentación 0 - Programación Básica

Increment and Decrement Operators

Basic programming review

Page 41: Presentación 0 - Programación Básica

Prefix and Postfix Example

Basic programming review

Page 42: Presentación 0 - Programación Básica

Java Primitive Types

Basic programming review

Page 43: Presentación 0 - Programación Básica

Arrays

Page 44: Presentación 0 - Programación Básica

Container object that holds a fixed number of values of a single type

Arrays are containers

Basic programming review

or

Page 45: Presentación 0 - Programación Básica

Arrays use example 1

Basic programming review

Page 46: Presentación 0 - Programación Básica

Arrays use example 2

Basic programming review

? ? ? ? ? ?

Page 47: Presentación 0 - Programación Básica

Arrays use example 2

Basic programming review

Page 48: Presentación 0 - Programación Básica

Arrays use example 3

Basic programming review

? ? ? ? ? ?

Page 49: Presentación 0 - Programación Básica

Arrays use example 3

Basic programming review

Page 50: Presentación 0 - Programación Básica

Working with multidimensional arrays

Basic programming review

Page 51: Presentación 0 - Programación Básica

Basic programming review

Method 2 (function)

Multidimensional array use example

Method 1 (function)

Page 52: Presentación 0 - Programación Básica

Multidimensional array use example

Basic programming review

Page 53: Presentación 0 - Programación Básica

1. Do the Eclipse HelloWord!! or NetBeans HelloWord!!

2. Modify the “Multidimensional array use example ”code in order to:

– print the main diagonal of the next two multidimensional arrays

Class Exercise

Basic programming review

1 2 3

4 5 6

7 8 9

a b c d

e f g h

i j k l

m n o p

Numbers array

Letters array

Page 54: Presentación 0 - Programación Básica

• [Deitel] H.M. Deitel and P.J. Deitel, Java How to Program: Early Objects Version, Prentice Hall, 2009.

• Oracle – Java Lesson: Language Basics

– http://download.oracle.com/javase/tutorial/java/nutsandbolts/index.html

References

Basic programming review