Project Zero

Project One
Objects
Bunny Bears using Turtles
Keep Calm and Carry On
Writing you first program
Java is a bad language to start programming in. There is code that needs to be included
to make a program run but you will not understand until much later. This is just
something you need to live with. It is like driving a car. You know how to use the
controls of a car (brake, steering wheel) but you really don’t know how those controls
work. As the year progresses the level of abstraction will decrease.
Let’s get started! Type this in Dr. Java.
This code will not
make sense until
much later.
Common errors:
1) When you save your program you must save it as the same name that you called
your class. In the above class you must save the file as BearBunnies. The name
is case sensitive.
2) All opening { must be followed by a closing }
3) Indent!!!
So now let’s see if our first program works. To run a program youse must do three
things.
1) Save your Program
2) Compile the program. This checks your program for errors.
3) Run the program.
If your program contains no errors it should do …..Nothing. Now our next step is to
make our program do something. The traditional first program is to make your program
print the words “Hello World” to the screen. Since I don’t hate you we will not do that.
We are going to play with Turtles.
First we need to create a world to put the turtles in. Someone else wrote a world class we
will be just using their code. It is kind of like driving a car. Someone else built it we just
use the controls.
So how does this look in code?
Compile and run the following.
PAUSE
Show Reichelson your world and get him to sign your paper here for 10
points.
Reichelson’s Signature: ______________ (10 points)
So your program did two things….
World turtleWorld ;
This line checks to see how much memory a World will take up. Then it reserves enough
memory to store a World and calls that memory turtleWorld. Note I did not have to name
my world turtleWorld. I could have called my world anything.
turtleWorld = new World( );
This line puts a physical World into the memory space called turtleWorld. The new
command creates babies from a blueprint. It is like building house from a blueprint.
Most programmers combine these two lines into one. Lets be lazy.
Lets review…
World turtleWorld = new World ( );
This created enough memory to store a World then named that World turtleWorld.
OK now lets focus on the ( ) part of the statement. The people who wrote the World class
let you set the size of the world when you create it.
Why we don’t have to memorize
An “API” allow programmers to use other programmer’s code without memorizing. I
currently forgot what API stands for.
World Summary (API)
World()
World that takes no arguments
Sets the world to a set size.
World(int w,int h)
World that takes a width and height
Sets the size of the world to your
two integers.
Try changing your world to a different size.
World turtleWorld = new World (200,200) ;
Experiment with different size worlds.
PAUSE
Show Reichelson your different sized world and get him to sign your
paper here for 10 points.
Reichelson’s Signature: ______________ (10 points)
Now let’s add some turtles to your turtleWorld.
When you create a Turtle you need to tell the Turtle where it will live. Was I born
knowing where Turtles live? Nope I just checked the API. ** There are no blank ( ) in
Turtle API **
You can also tell the Turtle where in the world to put it by including two integers. You
don’t have to memorize any of this. All of these options are listed in a thing called an
API. Don’t fret all programs that you need to know on the AP test have an API.
Memorizing UNNESSARY content will overwhelm you by filling up your brain bucket
and slowing you down.
PAUSE
Show Reichelson your World with a Turtle in it and get him to sign
your paper here for 10 points.
Reichelson’s Signature: ______________ (10 points)
Question One: What is the name of your World object? ____________________
Question Two: What is the name of your Turtle object? ____________________
You can make more than one turtle object(physical turtle) from one turtle class
(blueprint).
PAUSE
Show Reichelson your World with many turtles and get him to sign
your paper here for 10 points.
Reichelson’s Signature: ______________ (10 points)
What can a Turtles do? Check the Turtle API!
How do you make your turtle work? Object name dot method name.
Look here for examples.
How to add pictures….
Make sure you save your
picture under the same directory
as your java program. (Get
your pictures from the internet
or your phone)
Need to repaint the world to
see your picture.
Loops:
How to add up to infinity pictures without writing infinity lines of code.
Assignment 1
Make something pretty. I want something to do with a warren of bunnies doing
something cute with bears. The teacher (me) will be the sole judge of the cuteness. A
non cute output will not be accepted. Your program must include at least four Turtles
and a total of no less than 8 different Turtle methods. So hop to it. All worlds will be
displayed someplace so no violence. Your picture must make sense.
Extra credit will be awarded for the integration of unicorn and Bob Ross.
PAUSE
Show Reichelson your completed Assignment for 60 points.
Reichelson’s Signature: ______________ (60 points)
Extra credit for Unicorn / Bob Ross intergration.
Reichelson’s Signature: ______________ (5 points)