CSE 113 Week 3 January 28 – February 1, 2008

advertisement
CSE 113
Week 3
January 28 – February 1, 2008
Monday Announcements
 Software Installation Fest: 2/5 and
2/6 4pm – 7pm in Baldy 21
 Bring your laptop or desktop to have
appropriate software installed!
 Module 1 due 2/8
 Module 2 due 2/15
Monday Game Plan
 Exam 1
 More work with objects
Monday
 We can create a world
 We can create a turtle and put it in
the world
 If we assign the turtles to a variable,
then we can ask them to do things
Monday
 Things turtles can do:








moveTo(int, int)
turnRight()
turnLeft()
forward()
forward(int)
turn(int)
penUp()
penDown()
Wednesday Announcements
 Software Installation Fest: 2/5 and
2/6 4pm – 7pm in Baldy 21
 Bring your laptop or desktop to have
appropriate software installed!
 Exam 2 on 2/6
 Module 1 due 2/8
 Module 2 due 2/15
Wednesday Game Plan
 Vocabulary and terminology
Wednesday
 It is important to know the proper
terms for the things we are studying,
so we should make sure we clarify the
names of the programmatic elements
you have been working with so far
this semester.
Wednesday
 new Turtle()
 new is a keyword in Java. Keywords are
special to the language and can only be
used for a specific purpose. Java knows
these purposes, so every time it sees that
keyword it performs the exact same
operations each time.
 When it sees new, it knows we are about to
create a new instance of something.
Wednesday
 new Turtle()
 Turtle is the name of the class we are
creating an instance of, but in the
context of this entire statement,
Turtle is the name of a constructor
that we are trying to invomke.
Constructors for classes have the
same name as the class itself.
Wednesday
 new Turtle()
 The () are called a parameter list.
Parameter lists provide additional
information to a constructor when we
are calling it. Note that sometimes
our parameter lists have been empty
and other times we have needed to
put information inside them.
Wednesday
 new Turtle()
 This whole line is used when we are
creating an object.
 We can create an object and assign it
to a variable by using this code:
Turtle t = new Turtle();
Wednesday
 After we have a variable that refers to
our object, we can call methods on it
to ask the object to perform actions
for us.
 The syntax for a method call is:
object.methodName();
Wednesday
 object.methodName();
 object is the name of the object (the
name of the variable referring to the
object) that we would like to invoke
the method upon.
 methodName is the name of the
method we are trying to invoke
 () is another parameter list, can be
empty or have information.
Wednesday
 In order for the object to be able to
react to the method call, the method
must have been pre-defined inside
the code.
 Note that some methods that have
the same name (like forward in the
Turtle) can exist together. The reason
for this is because they take different
parameters.
Wednesday
 The grid the turtles live on is like the
coordinate plan you may have studied
in math class, but it has some key
differences you should know about.
 The origin (0,0) is in the upper left hand
corner.
 X-values increase going right
 Y-values increase as you go down
Friday Announcements
 Software Installation Fest: 2/5 and
2/6 4pm – 7pm in Baldy 21
 Bring your laptop or desktop to have
appropriate software installed!
 Exam 2 on 2/6
 Module 1 due 2/8
 Module 2 due 2/15
Friday Game Plan
 Working with Media (not Turtles)
 What happens when you reassign
variables that are referring to Turtles?
Friday
 There is a picture object that you can
create.
 It needs to know what the name of
the file is that should be displayed.
 You can get this by using the
FileChooser.pickAFile() method.
 There is a Sound object that can be
created as well.
Friday
 Variables that refer to Turtles and to other
objects as well are slightly different than
those that referred to numbers.
 If you have two turtles t1 & t2 defined and
you say:
 t1 = t2;
 Both t1 & t2 refer to the same turtle and
the turtle that is referred to by t1 is no
longer accessible in the program.
Download