Sunday, 6 March 2011

grid world page 35

1
Why doesn’t CrabCritter override theprocessActors() method?  
They both use the same code, no need to duplicate.  
2
Describe the process a CrabCritter uses to find and eat other actors.

Does it always eat all neighboring actors?

Explain.  
It collects positions of actors left, right or ahead of it, and then implements the eat method. Unless it’s a rock/critter.
3
Why is the getLocationsInDirections()method used in CrabCritter?  
getActors() gets all available positions to move into 
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?  
4,3
4,4
4,5 
5
What are the similarities and differences between the movements of a CrabCritter and a Critter?  
Left or right? Not sure 
6
How does a CrabCritter determine when it turns instead of moving?  
It turns when it cannot move anywhere
7
Why don’t the CrabCritter objects eat each other?  
Critters eat other objects in the field. That is the basis no?


grid world page 33-34

1
Why does act() cause aChameleonCritter to act differently from a Critter even though ChameleonCritter does not override act()?
Act method calls other methods differently  
2
Why does the makeMove() method of ChameleonCritter call super.makeMove?
Rest of the code for method is the same as in super class, the method calls on the super class methods instead of duplicating the code. 
3
How would you make theChameleonCritter drop flowers in its old location when it moves?
makeMove() has to be altered to drop flowers from the bug. 
4
Why doesn’t ChameleonCritter override the getActors() method?  
Using same methods from the superclass.  
5
Which class contains the getLocation()method?
Actor
6
How can a Critter access its own grid?  
getGrid()  method.


1
Why does act() cause aChameleonCritter to act differently from a Critter even though ChameleonCritter does not override act()?
Act method calls other methods differently  
2
Why does the makeMove() method of ChameleonCritter call super.makeMove?
Rest of the code for method is the same as in super class, the method calls on the super class methods instead of duplicating the code. 
3
How would you make theChameleonCritter drop flowers in its old location when it moves?
makeMove() has to be altered to drop flowers from the bug. 
4
Why doesn’t ChameleonCritter override the getActors() method?  
Using same methods from the superclass.  
5
Which class contains the getLocation()method?
Actor
6
How can a Critter access its own grid?  
getGrid()  method.

Sunday, 27 February 2011

GridWorld page 30



1
What methods are implemented inCritter?  
The following methods are implemented:
-          act()
-           getActors()
-           getMoveLocation()
-          electMoveLocation()
-          processActors()
-           makeMove() 
2
What are the five basic actions common to all critters when they act?  
They get actors and they process the actor, they get move locations, they choose a block to move to and finally they move. 
3
Should subclasses of Critter override thegetActors()   method?

Explain
They can have it, if they get actor, and want to change location or change the colour.   
4
Describe three ways that a critter could process actors.  
Rearrange the placements of the objects inside the  grid, removing all rocks, changing colour of the flowers
5
What three methods must be invoked to make a critter move?

Explain each of  these methods.  
Three methods are:
-          getMoveLocations()
-          selectMoveLocation()
-          makeMove()

1.       getMoveLocations() gives us a list of all the moving possible locations on the grid
2.       selectMoveLocation() selects a location on the list of locations
3.       makeMove then moves object to the chosen spot.   
6
Why is there no Critter constructor?  
It extends colour.


Grid World Page 25 and 26


1
Which statement(s) in the canMove() method ensures that a bug does not try to move out of its grid?  
If (!gr.isValid(next)) return false; 
2
Which statement(s) in the canMove()method determines that a bug will not walk into a rock?  
return (neighbor == null) || (neighbor instanceOf Flower); 
3
Which methods of the Grid  interface are invoked by the canMove()  method and why?  
Not sure.
4
Which method of the Location  class is invoked by the canMove() method and why?  
getAdjacentLocation() its checks if  the other blocks in the grid are valid so the object can move into the empty space.  
5
Which methods inherited from the Actor class are invoked in the canMove()method?  
getDirection
getLocation
get Grid
6
What happens in the move() method when the location immediately in front of the bug is out of the grid?  
The bug is automatically deleted from the grid. 
7
Is the variable loc needed in the move()method, or could it be avoided by callinggetLocation() multiple times?  
Getlocation method  
8
Why do you think the flowers that are dropped by a bug have the same color as the bug?  
Because they inherit the colour class from the bug 
9
When a bug removes itself from the grid, will it place a flower into its previous location?  
Yes it will
10
Which statement(s) in the  move() method places the flower into the grid at the bug’s previous location?  
Flower flower = new Flower(getColor());
11
If a bug needs to turn 180 degrees, how many times should it call the turn()method?  
four


GridWorld Page 23


1
Name three properties of every actor.  
The three fields are color, location and direction.
2
When an actor is constructed, what is its direction and color?  
The colour is blue and direction is set to  
3
Why do you think that the Actor class was created as a class instead of an interface?
4
Can an actor put itself into a grid twice without first removing itself? Can an actor remove itself from a grid twice? Can an actor be placed into a grid, remove itself, and then put itself back? Try it out. What happens?  
3. Firstly because some methods are implemented. 
4. It will give you an error if you try to put it in the grid twice. We are allowed to replace, that means placing something completely new instead of the old one, but you cannot put it in twice.
5
How can an actor turn 90 degrees to the right? 
by using the setdirection method. 

Sunday, 13 February 2011

Inheritance & Polymorphism

Over the weekend, we were supposed to do 28 multiple choices from the Barrons Book. Inheritance was very simple for me, its come to me like second nature because it was basically a review but I got stuck on Polymorphism. Unfortunately I got only 19 questions of these right and this time I did every single multiple choice question by myself. I did not get nay help on understanding and I did not want to slack of because I really believe that I need to apply myself more properly in this class, so I will be more focused in class this week and I will be on top of my coding. Apart from that, I did try to understand and solve the questions that I got wrong but Polymorphism is a concept which will take some time for me to understand like recursion did at the starting. Over the weekend, I also took the advise from Mr.Daly and I did like 15 JavaBat questions all from different sections like  I did some from Logic 2 and I did a few Recursion problems and some String-2 as well. Just so that I get better at the coding because I feel that my weakness is defiantly in the free response but I need to build up on it rather than slack it till later. I usually do well on multiple choice right. Also I tried  to go over the Sudoku coding that we did a while back, and I tried to code it myself. I saw that there was a lot of problem and confusion so I will be working on that throughout next week. Apart from this, I need to work on the grid world as well, which I will hopefully get done and post it tonight.