7
© A+ Computer Science - GridWorld Worksheet – www.apluscompsci.com Name : ___________________________ Date : _________________ Actor Activity One KEY Directions : Complete the activities and questions below. Use the appropriate GridWorld project folder and the GridWorld Student Manual. 1. Get a printed copy of the GridWorld Student Manual. 2. Open your GridWorld folder. This project contains the GridWorld.jar as well any needed files for this activity. 3. Open the GridWorld.ppt PowerPoint file. 4. Open the GridWorld project file – double-click on GridWorld.jcp. 5. Open the ActorOne.java file. 6. Compile the ActorOne.java file. 7. Execute ActorOne. 8. What happens/appears when you run ActorOne? A blue Actor appears in the grid at location 0,0. 9. What happens when you hit the step button? The blue Actor at 0,0 flips upside down and move from the right side of the cell to the left side of the cell. 10. What happens when you hit the run button? The blue Actor at 0,0 continually flips from the left to the right as well as going from right side up to upside down. 11. What happens when you hit the stop button? The blue Actor at 0,0 stops moving. 12. What is the default color of an Actor? Blue 13. What is the default movement pattern of an Actor? Back and forth and right side up to upside down while staying in the same cell. 14. Open ActorTwo and ActorThree and compile and execute them. What happens with each one? ActorTwo – a green Actor appears at location 2, 2 ActorThree – a yellow Actor appears at location 1,4

GW Activity Answer Key(1)

  • Upload
    rman202

  • View
    984

  • Download
    55

Embed Size (px)

DESCRIPTION

gridworld

Citation preview

Page 1: GW Activity Answer Key(1)

© A+ Computer Science - GridWorld Worksheet – www.apluscompsci.com

Name : ___________________________ Date : _________________

Actor Activity One KEY Directions : Complete the activities and questions below. Use the appropriate GridWorld project folder and the GridWorld Student Manual. 1. Get a printed copy of the GridWorld Student Manual. 2. Open your GridWorld folder. This project contains the GridWorld.jar as well any needed files for this activity. 3. Open the GridWorld.ppt PowerPoint file. 4. Open the GridWorld project file – double-click on GridWorld.jcp. 5. Open the ActorOne.java file. 6. Compile the ActorOne.java file. 7. Execute ActorOne. 8. What happens/appears when you run ActorOne? A blue Actor appears in the grid at location 0,0. 9. What happens when you hit the step button? The blue Actor at 0,0 flips upside down and move from the right side of the cell to the left side of the cell. 10. What happens when you hit the run button? The blue Actor at 0,0 continually flips from the left to the right as well as going from right side up to upside

down. 11. What happens when you hit the stop button? The blue Actor at 0,0 stops moving. 12. What is the default color of an Actor? Blue 13. What is the default movement pattern of an Actor? Back and forth and right side up to upside down while staying in the same cell. 14. Open ActorTwo and ActorThree and compile and execute them. What happens with each one? ActorTwo – a green Actor appears at location 2, 2 ActorThree – a yellow Actor appears at location 1,4

Page 2: GW Activity Answer Key(1)

© A+ Computer Science - GridWorld Worksheet – www.apluscompsci.com

Name : ___________________________ Date : _________________

Actor Worksheet 1 KEY Directions : Answer each of the questions below. Use the GridWorld documentation. 1. Explain method void act() and what purpose it serves? Sets the direction of this Actor to the opposite of its current direction. 2. Explain method int getDirection() and what it returns? Gets the direction of this Actor. 3. Explain method Location getLocation() and what it returns?

Gets the location of this Actor. 4. Explain method void moveTo(Location newLocation) and what purpose it serves?

Sets the location of this Actor to newLocation. 5. Explain method void putSelfInGrid(Grid<Actor> gr, Location loc) and what purpose it

serves?

Puts a reference to this Actor in grid gr at location loc. 6. Explain method void setDirection(int direction) and what purpose it serves?

Changes the current direction of the actor to that of direction. 7. Explain method void setColor(Color newColor) and what purpose it serves?

Changes the current color property of the Actor to newColor. Use the following code for questions 8-10. ActorWorld mars = new ActorWorld(); 8. Instantiate an actor named pablo. Actor pablo = new Actor(); 9. Change pablo’s color to GREEN. pablo.setColor(Color.GREEN); 10. Add pablo to the world at location (3,3). mars.add(new Location(3,3), pablo);

Page 3: GW Activity Answer Key(1)

© A+ Computer Science - GridWorld Worksheet – www.apluscompsci.com

Name : ___________________________ Date : _________________

Actor Worksheet 2 KEY Part 1 - directions : Complete the class below. You may use the GridWorld Quick Reference. //GoWestActor will move WEST. //GoWestActor will always stay in the same row. //GoWestActor should not go out of bounds when moving WEST. If GoWestActor reaches column 0, it should

move to the far right column while staying in the same row.

public class GoWestActor extends Actor { public void act() { Location aLoc = getLocation(); //get this actor’s current location Grid<Actor> aGrid = getGrid(); //get this actor’s grid

if( aLoc.getCol() == 0 ) { moveTo( new Location(aLoc.getRow(), aGrid.getNumCols()-1) ); } else { moveTo( aLoc.getAdjacentLocation(Location.WEST) ); }

} }

Part 2 - directions : Write the code described below. You may use the GridWorld Quick Reference. Assume that GoWestActor works as specified regardless of what you have written above. //Write the the following code that would be found in GoWestActorRunner //Instantiate an ActorWorld named texas //Instantiate a GoWestActor named chuck - add chuck to the world at location (2,3) //Instantiate a GoWestActor named susan - add susan to the world at location(4,5) //Make the world show the actors after they have been added. ActorWorld texas = new ActorWorld(); GoWestActor chuck = new GoWestActor(); GoWestActor susan = new GoWestActor(); texas.add(new Location(2,3), chuck); texas.add(new Location(4,5), susan); texas.show();

Page 4: GW Activity Answer Key(1)

© A+ Computer Science - GridWorld Worksheet – www.apluscompsci.com

Name : ___________________________ Date : _________________

Location Activity One KEY Directions : Complete the activities and questions below. Use the appropriate GridWorld project folder and the GridWorld Student Manual. 1. Get a printed copy of the GridWorld Student Manual. 2. Open your GridWorld folder. This project contains the GridWorld.jar as well any needed files for this activity. 3. Open the GridWorld.ppt PowerPoint file. 4. Open the GridWorld project file – double-click on GridWorld.jcp. 5. Open the LocationOne.java file. 6. Compile the LocationOne.java file. 7. Execute LocationOne. 8. What happens/appears when you run LocationOne? (3,5) and (2,9) appear. 9. What is a Location? Location is a class stores row and column information. 10. What type of information does a Location store? Location stores row and column information. 11. Add more Locations to LocationOne? Add more Location references to LocationOne. 12. Open, compile, and run LocationTwo. What happens/appears when you run LocationTwo? (1, 9) (3, 9) (2, 10) (2, 8) 270 13. Open, compile, and run LocationThree. What happens/appears when you run LocationThree? 0 180 90 270 14. How is Location used in GridWorld? Location is used to specify the cell at which an Object reference is stored.

Page 5: GW Activity Answer Key(1)

© A+ Computer Science - GridWorld Worksheet – www.apluscompsci.com

Name : ___________________________ Date : _________________

Location Activity Two KEY Directions : Complete the activities and questions below. Use the appropriate GridWorld project folder and the GridWorld Student Manual. 1. Get a printed copy of the GridWorld Student Manual. 2. Open your GridWorld folder. This project contains the GridWorld.jar as well any needed files for this activity. 3. Open the GridWorld project file – double-click on GridWorld.jcp. 4. Use any of the Location example programs you need. 5. How many directions does Location contain? 8 directions are contained in Location. 6. How many turn angles does Location contain? 7 turn angles are contained in Location. Use the following code to answer questions 7 – 9. Location locOne = new Location(2,2); Location locTwo = new Location(1,5); 7. Write the code to print out the location to the NORTH of locOne. System.out.println(locOne.getAdjacentLocation(Location.NORTH)); 8. Write the code to print out the direction needed to get from locOne to locTwo. System.out.println(locOne.getDirectionToward(locTwo)); 9. Write the code to print out true if locOne and locTwo store the same row,col values. System.out.println(locOne.equals(locTwo)); 10. Complete the Do You Know? questions from page 19.

Page 6: GW Activity Answer Key(1)

© A+ Computer Science - GridWorld Worksheet – www.apluscompsci.com

Name : ___________________________ Date : _________________

World Activity KEY Directions : Complete the activities and questions below. Use the appropriate GridWorld project folder and the GridWorld Student Manual. 1. Get a printed copy of the GridWorld Student Manual. 2. Copy the appropriate GridWorld folder from the student server . This project contains the GridWorld.jar as well

any needed files for this activity. 3. Open the GridWorld.ppt PowerPoint file. 4. Open the GridWorld project file – double-click on GridWorld.jcp. 5. Open the GridWorldOne.java file. 6. Compile the GridWorldOne.java file. 7. Execute GridWorldOne. 8. What happens/appears when you run GridWorldOne? A 10 X 10 grid appears. 9. What happens when you hit the step button? Nothing changes as there are no objects in the grid. 10. What happens when you hit the run button? Nothing changes as there are no objects in the grid. 11. What happens when you hit the stop button? Nothing changes as there are no objects in the grid. 12. What happens when you click on an empty cell in the grid? A small i appears, but there are no drop-down menus. 13. What happens when you click on an occupied cell in the grid? There are no occupied cells. 14. What is GridWorld? A grid is row/column structure. A grid has 10 rows and 10 columns.

TEACHER NOTICE :: You must download the gridworld.jar file from the AP Central website. You must paste the gridworld.jar file into any of the provided gridworld projects. I have provided a document with detailed instructions regarding JCreator gridworld project creation.

Page 7: GW Activity Answer Key(1)

© A+ Computer Science - GridWorld Worksheet – www.apluscompsci.com

Name : ___________________________ Date : _________________

World Activity – Code Writing KEY Directions : Write the program described below. Write a program that contains the following : 1 ActorWorld, 1 Actor @ (1,1), 1 GREEN Bug @ (2,2), 1 RED Rock @ (3,3), 1 YELLOW Flower @ (4,4), and 1 Critter @ (5,5). ActorWorld world = new ActorWorld(); world.add(new Location(1,1), new Actor()); world.add(new Location(2,2), new Bug(Color.GREEN)); world.add(new Location(3,3), new Rock(Color.RED)); world.add(new Location(4,4), new Flower(Color.YELLOW)); world.add(new Location(5,5), new Critter()); world.show();