Name:
Period:
Date:

Computer Programming 1A

Assignment# 11: More Java

Objectives:

In this activity you will:

  • use parameters in java commands.
  • solve problems using java.
  • practice critical thinking through reading, writing, and speaking.

Algorithm for this activity:

  • Read the statements below.
  • Complete the scenario as described.
  • Write complete sentence answers to the questions below (use THIS document for your responses). Save it as Assignment#11 answers.
  • When you have answered the questions and completed the scenario, create a turn-in folder named 1-CP1-Assign#11-Last,First. Place your responses FILE in this folder along with the completed scenario.
  • Compress the turn-in folder and upload it to Mr. Gonzalez’s DropItTo.me.

In this assignment we will create a new scenario from scratch and use some of the methods from the Animal class to control an actor in our new scenario.

The following six steps guide you in making a new scenario and creating a background for the world.

  • Start Greenfoot and choose New… from the Scenario menu to create a new scenario.
  • Name the scenario Assign#11-Elysium. Be sure to carefully save it to your desktop and double check to see that it is there before doing anything else.
  • Find an image of clouds on the Internet and change its size so its width is 600 pixels. The height should be close to 400. If not, adjust it or find another image.
  • Add a subclass to the world named CloudCity and use the cloud image you just downloaded.
  • Open your CloudCity subclass and add your name and date where indicated in your CloudCity subclass.
  • Change the super command in CloudCity to super(120, 80, 5);
  • Compile and be sure it looks good.

Now, we will add an Animal class and add code to it to make it do everything that an Animal does.

  • Add a subclass named Animal to the Actor class. Do not use an image for this class.
  • Delete all the code from your Animal subclass. Yes, everything. It should be blank white.
  • Open any scenario that uses the Animal subclass and copy the Animal source code to your new Animal subclass, then close the scenario you just opened.
  • Compile and make sure you have no errors.

Now we’ll add an actor and look at some new (and old) Greenfoot commands.

  • Create a new subclass of Animal named Plane. Use the Airplane image from Greenfoot.
  • Place a Plane in the world. It is too big, so we’ll change its size.
  • Open the Images folder from inside your scenario folder.
  • Double click the Airplane image and change it to 50 X 50 and save it.
  • Open your Plane subclass and put your name and date where indicated.
  • Add this code to the act method, compile and run.

setLocation(30,20);Greenfoot.delay(1);

move();Greenfoot.delay(1);

turn(90);

move();Greenfoot.delay(1);

turn(90);

move();Greenfoot.delay(1);

turn(90);

move();Greenfoot.delay(1);

turn (90);

Greenfoot.stop

  • Once you are sure the above code functions correctly move it to a new method structured like this:

public void square()

{

(the code to trace the square goes here)

}

  • Then call the method from the act method like this:

public void act()

{

square();

}

Now, after running your scenario repeatedly, answer these questions in THIS document named Assignment#11 Answers.

1.What does the Greenfoot.delay(1); command do?Explain:

  1. Try removing it and running the program if you want to see what it does. What happened? Explain:

2.What is the parameter for Greenfoot.delay(1); ?Explain:

3.What does the Greenfoot.stop command do?Explain:

  1. Try removing it to see what happens. Explain:

4.Why is the Greenfoot.delay(1); command next to the move(); command and not under it? Explain:

  1. Does it make a difference in how the program runs? Explain:
  • Change the program so that each line that has a move(); command has more than one, like this:

move();move();move();Greenfoot.delay(1);

  1. Run the program. Try putting moremove() commands in a row. What Happened? Explain:

5.What is the effect of putting multiple move() commands one after another?Explain:

  • Create a new method named triangle so that the plane will trace the shape of a triangle, returning to its original starting position. Call your new method from the act method. Call Mr. Gonzalez to check your work.
  • When you are done your program should have two methods that each trace a different shape; a square and a triangle. When you compile and run the program it should be obvious to the user that the plane is tracing both shapes, one after another. (shapes are clear, and does not run too fast).

6.Did you complete this scenario?Explain:

7.How much effort did you put into it? Explain:

  1. In other words, was it hard and time-consuming, or were you able to waste time in class and still get it done? Explain:

8.What was the hardest part of this assignment? Explain:

Turn in your answers and the scenario as directed in the green text at the top of this page.