Monday, 28 February 2011
Sunday, 27 February 2011
Tuesday, 22 February 2011
Barons 357-374 Multiple Choice
How did you do on the multiple choice questions?
I did pretty well, I got only a few mistakes, and most were not conceptual.
Did you understand your errors?
Not all...
What do you not understand?
In the turning questions, I was confused. E.g. question 2 stated that when a bug turns it takes its direction and adds 45 degrees to it. So if it was South, it would be 180 + 45 = 225. Mathematically speaking, 225 degrees is South East not South West as the book said it was.
Grid World Part 4 Part 2
Gridworld: Part 4: Interacting Objects: Set 9: Page 35
Gridworld: Part 4: Interacting Objects: Set 9: Page 35
1 | Why doesn’t CrabCritter override the processActors() method? | It doesn't override the processActors() method because the implementation of the method in the critter class is to eat other actors, and the crab does the same with movement restrictions and eating restrictions. |
2 | Describe the process a CrabCritter uses to find and eat other actors. Does it always eat all neighboring actors? Explain. | After moving either left or right (depending on the random value) it will check if a neighbor which is not a rock and is a critter is in front, front left, or front right of it and remove it. It won't eat all neighboring actors if they aren't critters, or if they're a rock. This because of the implementation of the processActors() in the critter class. |
3 | Why is the getLocationsInDirections() method used in CrabCritter? | I am not sure about this question. I can't really understand the getLocationsInDirections() method. |
4 | If a CrabCritter has location (3, 4) and faces south, what are the possible locations for actors that are returned by a call to the getActors() method? | I was under the impression that getActors() returns all actors in the grid, but I assume it is only the locations around the critter, therefore they would be (2,3), (3,3), (4, 3), (2,4), (4,4), (2,5), (3, 5), (4, 5). |
5 | What are the similarities and differences between the movements of a CrabCritter and a Critter? | CrabCritter moves in each call of act(), just as critter does; however, it can only move right, left, or turn 90 degrees either left or right, and relies on random values in order to determine its movement. |
6 | How does a CrabCritter determine when it turns instead of moving? | It checks whether it's movement is blocked in any direction. If it is, then it turns instead of moving. |
7 | Why don’t the CrabCritter objects eat each other? | I thought CrabCritter objects can eat each other... there seems to be no part of the code which suggests otherwise. |
Grid World Part 4 part 1
1 | page 30 What methods are implemented in Critter? The act(), getActors(), processActors(), getMoveLocations(), and selectMoveLocation() methods are implemented in Critter, although it still contains methods from it's superclass Actor. | ||||||||||||||||||
2 | What are the five basic actions common to all critters when they act? The actors are collected from the grid, they all invoke the processActors() method, they get their moves through getMoveLocations(), they select a location through selectMoveLocation(), and finally make a move through makeMove(). | ||||||||||||||||||
3 | Should subclasses of Critter override the getActors() method? Explain No, because the getActors() method is used to collect all actors on the grid, and if a subclass of critter overrides it, it might not even get to act because it won't be collected into the list of actors. | ||||||||||||||||||
4 | Describe three ways that a critter could process actors. It could change the state of the critter and the actor, it could change the state of the critter based on the actor, or change the actor (i.e. removing it). | ||||||||||||||||||
5 | What three methods must be invoked to make a critter move? Explain each of these methods. processActors(), getMoveLocations(), and selectedMoveLocation() must be implemented in order for the critter to move. | ||||||||||||||||||
6 | Why is there no Critter constructor? This is because the critter class is an abstract class. Furthermore, it implements methods for its subclasses to use, but can't make any objects. page 33
|
Wednesday, 16 February 2011
Barron's Polymorphism Multiple Choice
How did you do on the multiple choice questions?
I got most of them right, apart from one or two.
Did you understand your errors?
Yes. They were errors in understanding the question, but not conceptual.
What do you not understand?
I couldn't really understand the difference between polymorphism and overriding methods. From what I could understand, it seems overriding a method is simply redefining a method in a subclass, and polymorphism is using the correct overridden method in run-time. Is that precise?
Monday, 14 February 2011
Gridworld Part 3
Assume the following statements when answering the following questions. Location loc1 = new Location(4, 3); Location loc2 = new Location(3, 4); 1. How would you access the row value for loc1? | ||||||||||||||||||||||||||||||||||||||||||
1. loc1.getRow() would return the row value of loc1. 2. What is the value of b after the following statement is executed? boolean b = loc1.equals(loc2); 2. The value of b will be false because loc1 does not have the same values for row and column as loc2. | ||||||||||||||||||||||||||||||||||||||||||
3. What is the value of loc3 after the following statement is executed? Location loc3 = loc2.getAdjacentLocation(Location.SOUTH); 3. loc3 will have the values (4, 4). | ||||||||||||||||||||||||||||||||||||||||||
4. What is the value of dir after the following statement is executed? int dir = loc1.getDirectionToward(new Location(6, 5)); 4. dir will have the value 135 because Location(6, 5) is directly South East from loc1. | ||||||||||||||||||||||||||||||||||||||||||
5. How does the getAdjacentLocation() method know which adjacent location to return? 5. It knows which adjacent location to return by taking a direction as a parameter, which will direct it towards the requested location. pg. 21
|
Subscribe to:
Posts (Atom)