Introduction to Programming: Java Learning to Program Robotically INSTRUCTOR : Craig Duckett EMAIL :...
Preview:
Citation preview
- Slide 1
- Introduction to Programming: Java Learning to Program
Robotically INSTRUCTOR : Craig Duckett EMAIL :
cduckett@cascadia.edu
- Slide 2
- What is "Computer Programming" ?
- Slide 3
- What is Computer Programming? Computers don't do anything
without someone telling them what to domuch like the average middle
school student. To make the computer do something useful, you must
give it instructions in either of the following two ways: Write a
program that tells a computer what to dostep by stepmuch as you
write out a recipe. Buy a program that someone else has already
written that tells the computer what to do. Ultimately, to get a
computer to do something useful, you (or somebody else) must write
a program. A program does nothing more than tell the computer how
to accept some type of input, manipulate that input, and spit it
back out again in some form that humans find useful.
- Slide 4
- Programming is Problem-Solving Essentially, a program tells the
computer how to solve a specific problem. Because the world is full
of problems, the number and variety of programs that people can
write for computers is practically endless. But to tell a computer
how to solve one big problem, you usually must tell the computer
how to solve a bunch of little problems that make up the bigger
problem. If you want to make your own video game, for example, you
need to solve some of the following problems: Determine how far to
move a figure (such as a car, a spaceship, or a man) on-screen as.
Detect whether the figure bumps into a wall, falls off a cliff, or
runs into another figure on-screen. Make sure that the figure
doesn't make illegal moves, such as walking through a wall. Draw
the terrain surrounding the cartoon and make sure that if the
figure walks behind an object such as a tree, the tree
realistically blocks the figure from sight. Determine whether
bullets that another figure fires are hitting the player's figure.
If so, determine the amount of damage, how it affects the movement
of the damaged figure, and how the damage appears on-screen. The
simpler the problem is that you need to solve, the more easily you
can write a program that tells the computer how to work. A program
that displays a simple Ping-Pong game is much easier to write than
a program that displays World War II fighter airplanes firing
machine guns and dropping bombs on moving tanks while dodging
anti-aircraft fire in a smoke-filled sky.
- Slide 5
- Programming isnt Difficult, but Time-Consuming Programming
really isn't that difficult or mysterious. If you can write
step-by-step instructions directing someone to your house, you can
write a program. The hardest part about programming is identifying
all the little problems that make up the big problem that you're
trying to solve. Because computers are completely mindless, you
need to tell them how to do everything and also how to continue
when something unexpected happens. This means thinking through many
what if scenarios. Like Philosophers and other wooly thinkers,
Programmers are constantly questioning and considering all the
various ifs, ands, and buts of logic and decision-making. What
if?
- Slide 6
- Philosophers & Programmers What do they have in common
besides pondering and logic? Everybody else in the world
Philosophers & Programmers
- Slide 7
- Still Even though most of us practice philosophical thinking
and the components of logic and decision-making hundreds of times a
day we just dont do it for a living or make a career out of it. And
why? Most people are not cut out to be philosophers or programmers.
Most people dont get whatever it is that philosophers and
programmers get and it is for this reason, most people are not
philosophers or programmers. Philosophers and programmers are a
rare and often solitary breed. Now, going forward, lets consider
Logic thinking & Decision-Making
- Slide 8
- Logical Thinking
- Slide 9
- But First, A Simple Puzzle Can you make a necklace that costs
no more than 15 cents using the four chains below? It costs 2 cents
to open a link and 3 cents to close it again. If you're like most
people, you'll be blind to the correct answer because you'll become
fixated on the answer that seems immediately logical. But immediate
logic might not always be the best path of action.
- Slide 10
- But First, A Simple Puzzle Immediate logic might suggest that
we line up the four chains like this and open and close a link at
each other four corners, but this wont work because 4 (corners) x 2
(open) x 3 (close) = 20, and we only have 15 cents. The trick is to
come up with a way where we can do 3 x 2 x 2 = 15. Luckily, there
is. Instead of looking at the number of chains, we might look at
the number of links in one chain. 1 2 3 4
- Slide 11
- A Simple Solution If we were to open all the links in a single
chain that would cost use 6 cents, leaving 9 cents remaining for
closing the links, for a total of 15.
- Slide 12
- A Simple Solution Now we have three chains with three corners,
and three separate links to create the necklace. 3 (corners) x 2
(open) x 3 (close) = 15 Problem solved! 1 2 3
- Slide 13
- Decision Making
- Slide 14
- Now, A Simple Scenario The Task: Directions 1. Go from Point A
to Point B
- Slide 15
- Where Things Could Go Wrong The Task: 1. Go from Point A to
Point B 2. Watch for passing cars at the Intersections OR 3. Treat
Intersections as 4-Way Stops
- Slide 16
- Decisions, Decisions The Task: 1. Go from Point A to Point B 2.
Stop at all Intersections (2-way stops going North and South) 3.
Watch for cars going West and East before going through the
Intersections.
- Slide 17
- Different Decisions NOT Based on Directions The Task: 1. Go
from Point A to Point B 2. Treat Intersections as 4-Way Stops 3.
Consider rules of Right of Way before going through the
Intersection a) Car to left b) Car to right c) Car ahead, not
turning d) Car ahead, turning 4. Unexpected things: IF / ELSE / OR
/ AND
- Slide 18
- More Decisions The Task: 1. Go from Point A to Point B 2. Treat
Intersections as 4-Way Stops 3. Consider rules of Right of Way
before going through the Intersection a) Car to left b) Car to
right c) Car ahead, not turning d) Car ahead, turning 4. Unexpected
things: IF / ELSE / OR / AND
- Slide 19
- Alternative Decisions The Task: 1. Go from Point A to Point B
2. Treat Intersections as 4-Way Stops 3. Consider rules of Right of
Way before going through the Intersection a) Car to left b) Car to
right c) Car ahead, not turning d) Car ahead, turning 4. Unexpected
things: IF / ELSE / OR / AND
- Slide 20
- Different Decisions The Task: 1. Go from Point A to Point B 2.
Consider rules of Green / Red / Yellow before going through the
Intersection a) Red - STOP b) Green - GO c) Yellow - CAUTION 3.
Unexpected things: IF / ELSE / OR / AND
- Slide 21
- Unexpected Decisions The Task: 1. Go from Point A to Point B 2.
Consider rules of Green / Red / Yellow before going through the
Intersection a) Red - STOP b) Green - GO c) Yellow - CAUTION 3.
Unexpected things: IF / ELSE / OR / AND Tree Across Roadway Power
Lines Across Roadway Gravel in Roadway Glass/Metal in Roadway
- Slide 22
- Different Decisions The Task: 1. Go from Point A to Point B 2.
Consider rules of Green / Red / Yellow before going through the
Intersection a) Red - STOP b) Green - GO c) Yellow - CAUTION 4.
Unexpected things: IF / ELSE / OR / AND
- Slide 23
- Programming is All About Decision Making, Logic, & Memory
Do While If Then Or Else And Or True False Fail Gracefully and
Meaningfully All this DECISION MAKING has to be STORED and TRACKED
somewhere!
- Slide 24
- And Avoiding Errors/Crashes/Blue Screens
- Slide 25
- But How Does It All Work? Central Processor Unit (CPU) Memory
Storage Input/Output (I/O) Keyboard Mouse Monitor Speakers
Network
- Slide 26
- Memory RAM (Random Access Memory) DRAM (Dynamic)
- Slide 27
- Memory Storage Cells "Allocated Memory Locations"
http://static.howstuffworks.com/flash/ram-virtual.swf
- Slide 28
- Memory Text Characters ASCII (American Standard Code for
Information Interchange) Play Video
- Slide 29
- Java Memory Throughout the quarter, instead of calling these by
their correct name, Allocated Memory Locations, I will usually just
called them "Buckets".
- Slide 30
- Programming Paradigms Procedural (Top Down Function Driven)
Object Oriented (Class and Object Driven)
- Slide 31
- Procedural Programming Programs in the past used a procedural
process for development where a program performed in series of
steps, in a linear fashion and the focus was on steps as shown
below:
- Slide 32
- Object-Oriented Programming In object-oriented programming, the
focus is on real world objects which interact with each other.
Objects in turn have state, attributes and operations. Objects are
viable things that do something. Objects perform actions.
- Slide 33
- Class, Objects, and Methods: Here Comes the Hippy-Dippy
Stuff!
- Slide 34
- Class: Example Using Language Animal Mammal Breed Fur Barks
Plays fetch Digs Chase cats Eats Sleeps Etc.
- Slide 35
- Class: Example Using Language Animal Mammal Breed Fur Barks
Plays fetch Digs etc Mammals are air-breathing vertebrate animals
characterized by the possession of endothermy, hair, three middle
ear bones, and mammary glands functional in mothers with young. The
word "animal" comes from the Latin word animalis, meaning "having
breath". The biological definition of the word refers to all
members of the kingdom Animalia, encompassing creatures as diverse
as fish, reptiles, birds, mammals, and insects.
- Slide 36
- From Consensus Class Object
- Slide 37
- We think in terms of Class all the time For instance, do you
understand this sentence? The dog chased the ball into the street
and nearly got hit by the car. Okay, if you understand this
sentence, then What kind of dog was it? What kind of ball was it?
What kind of street was it? What kind of car was it?
- Slide 38
- Class Objects Dog Ball Street Car General Attributes Specific
Properties and Actions Specific Properties and Actions Specific
Properties and Actions Specific Properties and Actions
- Slide 39
- Class Object In Object-Oriented Programming, a Class is like a
cookie cutter and dough, and Objects are like the unique cookies
made from them
- Slide 40
- Class Class Object In Java, the various things (actions) that
Objects do are called Methods PersonWithCapAndBag EXTENDS
Person
- Slide 41
- Dot Notation Mailman.fillBag(); Mailman.deliverMail();
Mailman.pickUpMail(); Mailman.putMailInBag();
Mailman.runFromBigDog(); Paperboy.fillBag();
Paperboy.deliverPaper(); Paperboy.runFromBigDog();
Paperboy.drinksSlurpee(); Paperboy.collectsPayment(); ObjectMethod
ObjectMethod
- Slide 42
- What you will learn in this Introduction to Programming class
is just the "tip of the iceberg" but it will establish a firm
foundation for you to confidently go on to learn and excel in other
programming languages.
- Slide 43