360 likes | 545 Views
BIT 115. Introduction to Programming: Java Learning to Program Robotically. INSTRUCTOR : Craig Duckett EMAIL : cduckett@cascadia.edu. What is Computer Programming?. Computers don't do anything without someone telling them what to do—much like the average middle school student.
E N D
BIT 115 Introduction to Programming: Java Learning to Program Robotically INSTRUCTOR: Craig Duckett EMAIL: cduckett@cascadia.edu
What is Computer Programming? • Computers don't do anything without someone telling them what to do—much 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 do—step by step—much 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.
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.
Programming isn’t 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 problemsthat make up the big problem that you're trying to solve. Because computers are completely mindless, you need to tell them how to do everythingand 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…?”
Philosophers & Programmers What do they have in common besides pondering and logic? Everybody else in the world Philosophers | Programmers
Still … Even though most of us practice philosophical thinking and the components of logic and decision-making hundreds of times a day … … we just don’t 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 don’t “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 on, let’s consider Logic & Decision-Making …
A Simple Scenario… The Task: Directions 1. Go from Point A to Point B
…Where Things CouldGo 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
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.
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
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
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
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
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
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
Programming is All About Decision Making, Logic, & Memory Do … While If … Then Or … Else And … Or True … False … Fail Gracefullyand Meaningfully All this DECISION MAKINGhas to be STORED and TRACKED somewhere!
But How Does It All Work? • Central Processor Unit (CPU) • Memory • Storage • Input/Output (I/O) • Keyboard • Mouse • Monitor • Speakers • Network
Memory • RAM (Random Access Memory) • DRAM (Dynamic)
Memory Storage Cells"Allocated Memory Locations" http://static.howstuffworks.com/flash/ram-virtual.swf
Memory Text Characters ASCII (American Standard Code for Information Interchange) Play Video
Java Memory Throughout the quarter, instead of calling these by their correct name, Allocated Memory Locations, I will usually just called them "Buckets".
Programming Paradigms • Procedural (Top Down “Function” Driven) • Object Oriented(“Class” and “Object” Driven)
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:
Object-Oriented Programming In object-oriented programming, the focus is on real world objects which interact with each other. Objects in turn have state, attributesand operations. Objects are viable things that do something. Objects perform actions.
Class , Objects, and Methods:Here Comes the Hippy-Dippy Stuff!
Class: Example Using Language “Dog” • Animal • Mammal • Breed • Fur • Barks • Plays fetch • Digs • Chase cats • Eats • Sleeps • Etc. …
Class: Example Using Language Animal 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 . 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. Mammal • Animal • Mammal • Breed • Fur • Barks • Plays fetch • Digs • etc … “Dog”
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?
“Class” Objects “Dog” “Ball” “Street” “Car” General Attributes General Attributes General Attributes General Attributes Specific Properties and Actions Specific Properties and Actions Specific Properties and Actions Specific Properties and Actions
Class Object In Object-Oriented Programming, a Classis like a cookie cutter and dough, and Objectsare like the unique cookies made from them
Class Class Object PersonWithCapAndBag EXTENDS Person In Java, the various things (actions) that Objects do are called Methods
Dot Notation Mailman.fillBag(); Mailman.deliverMail(); Mailman.pickUpMail(); Mailman.putMailInBag(); Mailman.runFromBigDog(); Paperboy.fillBag(); Paperboy.deliverPaper(); Paperboy.runFromBigDog(); Paperboy.drinksSlurpee(); Paperboy.collectsPayment(); Object Method Object Method
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.