Basic programming review
Sebastian Alejandro Velasco
Object Oriented Programming
Basic programming review
Agenda
Basic
concepts
Control
Structures
Operators
Basic programming review
Arrays
Basic concepts
Algorithm
Flow diagram
Pseudo code
Basic programming review
An algorithm is a step-by-step procedure
Any computing problem can be solved by executing
a series of actions in a specific order.
Finite
Deterministic
Basic programming review
Precision
An algorithm is a step-by-step procedure
Problem that we want to solve
Going to work
Basic programming review
Algorithms can be represented in several ways
Pseudo Code
Flow diagram
chart
UML activity
diagram
Basic programming review
Pseudo codes are informal descriptions of algorithms
Informal descriptions or languages help programmers to
develop algorithms without having to worry about the strict
details of a programming language syntax.
All pseudo codes should be:
Set grade counter to one
While grade counter is less than or equal to ten
Human readable
Can easily be converted to any
programming language
Input the next grade
Add the grade into the total
Set the class average to the total divided by ten
Print the class average.
I am a pseudo code
Basic programming review
Flow diagrams are used to represent algorithms
Tape
Document
Input or
output
Begin or End
Process, task,
action, or operation
We are used to represent
processes flows
Page
connector
Subroutine
or function
Connector
Decision
Data
Storage
Resource: What do the different flowchart shapes
mean?
Basic programming review
These Flow diagram and Pseudo code are equivalent
Basic programming review
Activity diagrams describe the workflow of a system
Activities
Decisions
Start (split) or end (join) of
concurrent activities
The start (initial state) of the
workflow
The end (final state).
Basic programming review
Activity diagrams describe the workflow of a system
I am a UML activity diagram
Basic programming review
Control Structures
Sequence Structure
Selection Statements
Repetition Statements
Control Structures
Programs are formed by combining as many
sequence, selection and repetition statements.
selection
repetition
if
while
ifelse
dowhile
switch
for
Basic programming review
Sequence structure
An ordered execution of two or more
statements are called sequence structure
Basic programming review
IF Selection Statement
If students grade is greater than or equal to 60
Print Passed
Basic programming review
IF..ELSE Selection Statement
If students grade is greater than or equal to 60
Print Passed
Else
Print Failed
Basic programming review
IF..ELSE Selection Statement abbreviated form
Basic programming review
Nested IF..ELSE Selection Statement
If students grade is greater than or equal to 90
Print A
else
If students grade is greater than or equal to 80
Print B
else
If students grade is greater than or equal to 70
Print C
else
If students grade is greater than or equal to 60
Print D
else
Print F
Basic programming review
Do not forget
Indent both body
statements of an if
else statement.
1
Always using braces in an ifelse (or
other) statement helps prevent their
accidental omission
Basic programming review
Do not be the beast
Ugly code is written by ugly people.
I like my code !!
Basic programming review
Do not worry, we can format the code automatically
ALT + Maysculas + F
Eclipse
NetBeans
CTRL + SHIFT + F
Basic programming review
WHILE Repetition Statement
While product is less or equal than 100
products
Multiply by 3 the number of products
Be careful with infinite loops!!
Basic programming review
FOR Repetition Statement
????
?
Basic programming review
FOR Repetition Statement
Basic programming review
FOR Repetition Statement
Basic programming review
FOR Statements header examples
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: ?, ?, ?, ?, ?,?, ?, ?, ?, ?
Basic programming review
FOR Statements header examples
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
Basic programming review
FOR Statement example
Basic programming review
DOWHILE Repetition Statement
Remember always include braces !!!
Basic programming review
SWITCH Multiple-Selection Statement
Basic programming review
SWITCH Multiple-Selection Statement
What is the difference?
Basic programming review
BREAK and CONTINUE Statements
Break
Continue
Basic programming review
Basic programming review
Summary
Basic programming review
Operators
Logical Operators
Assignment Operators
Increment and Decrement Operators
Logical Operators
Conditional AND (&&)
Conditional OR (||)
Logical Negation (!)
Basic programming review
Logical Operators - Truth tables
Basic programming review
Assignment Operators
variable = variable operator expression;
Basic programming review
Compound Assignment Operators
Basic programming review
Increment and Decrement Operators
Basic programming review
Prefix and Postfix Example
Basic programming review
Java Primitive Types
Basic programming review
Arrays
Arrays are containers
Container object that holds a fixed number of
values of a single type
or
Basic programming review
Arrays use example 1
Basic programming review
Arrays use example 2
????
??
Basic programming review
Arrays use example 2
Basic programming review
Arrays use example 3
????
??
Basic programming review
Arrays use example 3
Basic programming review
Working with multidimensional arrays
Basic programming review
Multidimensional
array use example
Method 1
(function)
Method 2
(function)
Basic programming review
Multidimensional array use example
Basic programming review
Class Exercise
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
1
Numbers
array
Letters
array
Basic programming review
References
[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
Basic programming review