Nt1310 Unit 6 Research Paper

524 Words2 Pages

I. Set 3 1. Loc1.getRow() 2. False 3. (4,4) 4. 135 degrees or southeast 5. The parameter in the getAdjacentLocation method indicates the direction of the adjacent neighbor to find. It then returns the adjacent location in the direction that is closest to the direction given in the parameter list. II. Set 4 1. Use the variable z and assume that z is a Grid object. z.getOccupiedLocations().size(); this will find the amount of occupied locations in the grid. z.getNumRows()*z.getNumCols() – z.getOccupiedLocations().size(); This will find the number of empty locations in a BoundedGrid object. 2. z.isValid(new Location(10,10)) 3. You will find the implementations of the methods in the AbstractGrid, BoundedGrid, and UnboundedGrid classes. Because …show more content…

It could be better to use an Array because the notation could be easier. Instead of using locs.get(j), you could use locs[j]. Also, if Grid could keep track of the number of occupied locations, then filling an array would be pretty much just as easy as filling in an ArrayList. III. Set 5 1. Direction, location, color 2. North, blue 3. Because an interface does not allow the programmer to declare instance variables or implement methods. Interfaces only have states, not behavior, and Actor has both. So therefore, a class is used. 4. No, an actor cannot put itself into a grid twice without removing itself; IllegalStateException. No an actor cannot remove itself from a grid twice;IllegalStateException. Yes, an actor can be placed into a grid, remove itself, and then put itself back; this would run without an error 5. You could use the setDirection method. setDirection(getDirection() + Location.RIGHT) or you could use setDirection(getDirection()+90). IV. Set …show more content…

Actor neighbor = z.get(next); Return (neighbor == null) || (neighbor instanceOf Flower); 3. isValid and get are invoked by the canMove method. These methods check to see if the next location is a valid location in the grid and also to ensure that the object in that location is empty. 4. getAdjacentLocation. This method is called by the bug with the direction the bug currently holds in order to find its net possible location 5. getDirection, getLocation, getGrid 6. The bug will then remove itself from the grid. 7. Yes it is needed. This variable stores the location of the bug before it moves. It is therefore used to insert a flower in the bug’s previous location. 8. Probably because it is easier to tell which bug dropped the flower since they will have the same color. 9. It depends on which method you used. If you used the removeSelfFromGrid method, then it would place a flower into the bug’s previous location. However, if you used the removeSelfFromGrid method, then no, it would not place a flower in the bug’s previous location. 10. Flower flower = new Flower(getColor()); flower.putSelfInGrid(z, loc); // assume z is a Grid object. 11. It should call the turn method 4 times since each time it is called the bug turns in 45 degree increments. So 4*45 =

More about Nt1310 Unit 6 Research Paper

Open Document