Lesson 1: Writing a program. Java Java is a programming language Computer cannot understand it, though it can be translated ( compiled ) so a computer.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Starting to program with BlueJ and the Beetle - a 2 day course for real beginners Lynda Thomas
 Variables  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
Getting to know Greenfoot
Games and Simulations O-O Programming in Java The Walker School
Animation Mrs. C. Furman. Animation  We can animate our crab by switching the image between two pictures.  crab.png and crab2.png.
Chapter 2 - The First Program: Little Crab
Program: Little Crab Mr Gano.
Wombats Creating Games with Greenfoot The Walker School – Games and Simulations
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
CMT Programming Software Applications
Introduction to a Programming Environment
Chapter 9 Interactive Multimedia Authoring with Flash - Introduction to Programming “Computers and Creativity” Richard D. Webster, COSC 109 Instructor.
Real World Programming BBrewer Fall Programming - Bellwork 1.Log on 2.Go to edmodo 3.Open & Save Vocabulary Graphic Organizer and Analaysis Document.
Welcome to the CRE Programming Club! Robert Eckstein and Robert Heard.
Created by NW 2012 – please note all copyright on images used is property of copyright holder. Note: some of the more complicated descriptions are taken.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
An Introduction to Textual Programming
Java: Chapter 1 Computer Systems Computer Programming II.
Greenfoot. Getting Started Open the Greenfoot download site: Select Greenfoot
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Chapter 1 - Getting to know Greenfoot
What does a computer program look like: a general overview.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Lecture 4. Greenfoot 1 Pablo Romero, Department of Informatics Greenfoot Programming simulations and games in Java.
Game Maker Terminology
PROGRAMMING In Lesson 2. STARTER ACTIVITY Complete the starter activity in your python folder – lesson 2 Now we will see how you got on and update your.
Greenfoot Game Programming Club.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Classes Java and other Object-Orientated Programs or OOP are based on the creation and interaction of classes. Every program in Java has at least one class.
Can I get your number? By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Kakihijau.googlepages.com Introduction To Greenfoot Part-1.
Lesson 2: Reading a program. Remember: from yesterday We learned about… Precise language is needed to program Actors and Classes Methods – step by step.
Introduction To Greenfoot
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Introduction to Computer Programming - Project 1 Intro to Digital Technology.
Chapter 2 – The Little Crab Program:. Little Crab Scenario Inheritance: The Arrows Denote Hierarchy Crab is an Animal Animal is an Actor Therefore, It.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
Introduction to TouchDevelop Lesson 3 – Comments & Lists Created by S. Johnson
Today's Ninja Challenge: Write Your First Computer Game!
Programming for Interactivity Professor Bill Tomlinson Tuesday & Wednesday 6:00-7:50pm Fall 2005.
Adding and Eating Worms Mrs. C. Furman August 23, 2010.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Comp1004: Introduction III Java. Content How Java Works: The JVM Writing a Class in Java – Class – Member Variables – Method – Statement Magic incantations.
1 Quiz Show Programming Terms. 2 Alice - 3D Virtual Programming Vocabulary Quiz Board Chapter 1 Chapter 2a Chapter 2b Chapter 3 Chapter 4 $100 $200 $300.
Chapter 4 - Finishing the Crab Game
Content Programming Overview The JVM A brief look at Structure – Class – Method – Statement Magic incantations – main() – output Coding a Dog Programming.
Greenfoot.
Chapter 4 - Finishing the Crab Game
Content Programming Overview The JVM A brief look at Structure
Introduction to Computer Science / Procedural – 67130
Introduction To Greenfoot
Debugging and Random Numbers
IF statements.
Creating Games with Greenfoot
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Version 2.
The Little Crab Scenario
Organizing Memory in Java
Introduction to TouchDevelop
ICT Gaming Lesson 3.
Methods, Data and Data Types
Greenfoot November 8, 2009.
User Input Keyboard input.
Unit 3: Variables in Java
Bishopston Comprehensive School
Presentation transcript:

Lesson 1: Writing a program

Java Java is a programming language Computer cannot understand it, though it can be translated ( compiled ) so a computer can understand it Computers only understand precise and correct language; they are more picky than your English or French teachers

Java Like with other languages (English, French, Spanish) you must learn the words, meaning, and syntax. You must correctly express yourself or the computer will misunderstand. Little details matter. Where you put a semi- colon can change the meaning.

Precise Language Let’s eat Grandpa! Let’s eat, Grandpa! Punctuation saves lives.

Precise Language Stop clubbing baby seals!

Structure of a program Programs are broken into classes – Actors in Greenfoot Classes have methods – Stuff they can do Classes have properties – Details that describe them Methods have instructions – What to do and when to do them

Classes Classes represent idea or type of thing – Example: cups, humans, wombats, walls A class generically describes the type – Humans have a name, 2 arms, age, height, etc. A class defines generic actions – Humans can walk, eat, sleep, turn A class can be a sub type – A human is an animal, a dog is an animal, a cup is NOT an animal

Describe a dog What are some properties of dogs? What are some sub-parts of a dog? What actions can a dog take? A dog a special type of something? – Are there special types or different types of dogs?

Describe a cat What are some properties of dogs? What are some sub-parts of a dog? What actions can a dog take?

Methods Classes can have methods (commands) that can be given to anything of this type These are like set of instructions to accomplish something Example telling any human to walk Example telling a dog to sit

Methods Make ice cream – Place 2 cups whipping cream, 1 cup milk, ¾ a cup of sugar, a little vanilla in a bowl. – Mix the ingredients in bowl – Place in ice cream maker to freeze contents.

Methods Define word (eg. Define gregarious) – If I know the meaning Tell professor – Otherwise if I have internet access Look it up online Tell professor – Otherwise Find a dictionary Look it up Tell professor

Classes Let’s take a look Open the wombat “scenario” Double click to open the WombatWorld class

Let jump in and all some methods! Open Exercise 1 Let make the wombat move Double click Find the act() method and call move

But he just gets stuck! Each time the game updates the act method is called. So the wombat just keeps moving forward as the game progresses. Can we make him turn with the turn method? turn requires a number of degrees to turn Try: turn( 30 )

Now he goes in circles. That’s not fun! Can we use methods to control him? Yes. We will ask Greenfoot what keyboard button is pressed, then do something. We will tell the computer if( question ) then something if( “a” is pressed down ) then turn and go left

Now let’s add controls for all directions! We will use a for left (180), w for up (270 or -90), s for down (90), and d for right (0).

Calling a method method_name( argument1, argument2 ); Example of commands: turn( 90 ); turn ( 180 ) ; move(1 ); Some spaces don’t matter, but the CAPITAL or lowercase letters do. A command/statement ends in a semi-colon!

If statements If statements are used to control the flow of a program – What part do we want to run when? – Just like we only want the wombat to turn when a key is pressed The question must be true or false – It computer terms we call this a boolean value

If statements if( boolean_value ) { // Do something when boolean_value = true // Put as many instructions as you want between funny braces { } } else { // do something when boolean_value = false } Notice there are no semi-colons

if( boolean_value ) doOneThing(); else doOneOtherThing(); If statements can also look like this Notice there are no braces and one command

Can we use if statements to eat leaves? Let’s make the wombat eat leaves We will use the foundLeaf() and eatLeaf() methods already in the wombat. foundLeaf return a boolean value if the wombat is on a leaf

Can we use if statements to eat leaves?

What if we don’t want to move when we are eating? Or we only move when we are not eating?

Let’s add a sound for eating If your computer has a microphone, you can record a sounds Go to the menu “Controls > Show sound recorder” Click record

Let’s add a sound for eating Run a search for “eating wav” “.wav” is the type sound file we would like Websites like soundbible.com and have free sounds. Find a sound you like Download it Place it in the “lesson 1\sounds” folder

Let’s add a sound for eating Now we just have to call Greenfoot.playSound( “filename.wav” ); For example I have provided a chomp chomp sounds. Try Greenfoot.playSound( “ChompChompChomp.wav” );

Objects, Variables, and Primitives How do we store values, objects, and information for later use? – Number of leaves eaten – Position – Lists of leaves How do we update information? – Increase the number of leaves eaten – Removing a leaf from a list

Variables We use a variable to store information A variable as a type, name, and value – Type is what kinds of things it can store – Name is used to indicate which information we want – Value is the specific thing it is currently store

Examples Type/Value – Number Age 10 – Number OtherNumber 12 – Decimal numberPi3.14 – Text Preferences ”I like monkeys”

Example in Java int age= 10; int otherNumber = 12; double Pi = 3.14; String preferences = “I like monkeys”;

References When you refer to an Object or Actor you must use a reference. – You don’t store the Actor, you refer to them – You want the actor to keep doing their job – References are like other variables Personmartin (Create a new Person Called Martin) Actorprofessor martin List of LeavesremainingLeaves (list of remaining leaves) ActorkingOfCanadaNone;

Example in Java // Assume a Person is a type of actor Person martin = new Person( “Martin” ); Actor professor = martin; List remaingLeaves = getObjects(Leaf.class); Actor kingOfCanada = null;

Stopping the game Let’s stop the game when all the leaves are eaten Open the WombatWorld Code Add an public void act() method Get the remaining list of the Leaves If there are none, stop

Stopping the game Lists have many built in methods isEmpty return a boolean (true or false) depending on if the list is empty (contains nothing) We can find documentation by searching for “Java List”

Try your own ideas Add a sound at the end of the game Add rocks to the World (see populate()) Make it so you cannot walk over rocks or walk more slowly Add a second wombat, create a second Actor Give it different controls Try “left”, “up” “down”, “right” (the arrows)