CSI Lecture Programming Java Using Turtles

CSI Lecture Programming Java Using Turtles - CSI 201...

Info iconThis preview shows pages 1–21. Sign up to view the full content.

View Full Document Right Arrow Icon
CSI 201 Introduction to Computer Science Spring 2010 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
LECTURE 5 Wednesday, February 3, 2010 2
Background image of page 2
ANNOUNCEMENTS 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4
Background image of page 4
What’s in the NEW CCI Office? Tutoring Study groups Faculty Office hours Student/Club mee;ngs Open lounge Come play Wii! Located in LI ‐84 (between Computer Science office Informa2on Studies Advisement office ) Drop by LI‐84 for more informa2on! 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ICLICKER QUESTION 6
Background image of page 6
ICLICKER QUESTION A. Object B. Parameter C. Class D. Byte E. Meta What type of method is called in the following statement? SECONDS REMAINING Math.abs(7); 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
PROGRAMMING JAVA USING TURTLES 8
Background image of page 8
This material corresponds to chapter three in the text. Programming Java using Turtles 9
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CREATING OBJECTS IN JAVA In Java to create an object of a class you use new Class (value, value, …); For example, our Turtle objects live in a World object. We must create a World object ±rst Try typing the following in the interactions pane: new World (); 10
Background image of page 10
CREATING OBJECTS If you just do new World (); You will create a new World object and it will display. 11
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CREATING OBJECTS But you will not have any way to refer to your brave new world. Once you close the window the object can be garbage collected. The memory can be reused. We need a way to refer to the new object. to be able to work with it. 12
Background image of page 12
NAMING IS IMPORTANT If you get a new pet one of the Frst things you do is name it Gives you a way to refer to your new pet without saying - “Please take that dog we got yesterday for a walk.” Instead we can say - “Please take Spot for a walk.” 13
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
NAMING IS IMPORTANT This is especially important if you have more than one of that type of object. “Walk the dog.” “Which dog?” “Um…” 14
Background image of page 14
NAMING IS IMPORTANT In programming we name things we want to refer to. Gives us a way to work with them. Like the World object 15
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
SAVING A REFERENCE TO AN OBJECT To be able to refer to an object again we need to specify what type of thing it is and give it a name. We saw this when we were declaring variables of primitive types. Type name ; OR Type name = new Class (value, value, …); 16
Background image of page 16
SAVING A REFERENCE TO AN OBJECT Reminder - the equal sign doesn’t mean equal It means assign the value of the stuff on the right to the variable on the left. The following creates a variable named world1 which refers to a World object created on the right World world1 = new World (); 17
Background image of page 17

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
DECLARING VARIABLES Variables are names associated with values If the value of the variable is null it doesn’t refer to an object yet Variables can be reused 18
Background image of page 18
DECLARING VARIABLES Variables are names associated with values If the value of the variable is null it doesn’t refer to an object yet Variables can be reused World world1 = null ; world1 null 19
Background image of page 19

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Variables are names associated with values If the type of the variable is null it doesn’t refer to an object yet
Background image of page 20
Image of page 21
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/07/2011 for the course CSI 201 taught by Professor Doanne during the Spring '08 term at SUNY Albany.

Page1 / 64

CSI Lecture Programming Java Using Turtles - CSI 201...

This preview shows document pages 1 - 21. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online