Sunday 27 March 2011

Post on packet given last class

I got 6 question correct out of the 8 multiple choice.

I do not completely understand all my mistakes so I hope to go over them in class.

Regarding Codingbat:
I have code for several questions however they either wont compile or do not return a "all correct" message
I will ask Gershon or Elhanan for help on Monday

Tuesday 22 March 2011

Gridworld Practice Exam

I found the packet quite helpful seeing as it cleared some things up for me regarding Gridworld.

I got 5 correct out of 6 and found most of the question quite easy.

There was nothing in the packet which I did not actually understand. I even understood the question i got wrong. However, I find the level of the packet simpler than all the test being given in class.

Sunday 6 March 2011

Last Barrons Chapter

I did very well on the multiple choice questions on this chapter.. (only 3 wrong)

I understood my mistakes, they were mostly on the theoretical questions regarding programming

I understand this chapter very well and I feel very confident about it

Monday 28 February 2011

By 8:00pm Monday 28th in your blog

1. Barron’s Review (Some Standard Classes)
How did you do on the multiple choice questions?
Did you understand your errors?
What do you not understand?
2. Comment on, or proposal for GridWorld project
3. Implement caterpillar
4. 3 coding-bat problems
1)
 How did I do?
I got 17 questions right out of 22. I noticed that the easiest questions for me were those about strings.

Did I understand my errors?
I understood most of my errors yet some questions still confuse me especially regarding the Math class and the Random class.

What do I not understand?
I understand most of the material and I am sure I will get better with practice. I am a bit confused about the indexOf method and how it functions.

2)

 After going over the packet this project seems very interesting. I have sort of understood how the project should work and I understand the methods and purposes of each actor in the project. I am not sure what I am suppose to do by now but since you said to only comment at the moment, I shall wait for further instructions.
 I can already assume I will need quite a bit of help throughout this project. Hopefully, the packet is helpful enough so I will be able to work independently most of the time.

3)

My caterpillar class does not compile, I am also not sure that if it will compile it will work as intended. Hopefully I will be able to fix and understand my caterpillar implementation during our class.

4) I was not able to do any Array 3 or String 3. As you told me, I spoke to Gershon and he is more than willing to help me. However, he was not free today so he will assist me tomorrow. Thus, I will only have the codingbat exercises ready by Tuesday. Please take this into your consideration. Thanks in advance.

Thursday 24 February 2011

Barron’s Review (Gridworld)

How did you do on the multiple choice questions?

I got most of the multiple choice questions correct (8 wrong). 
Most questions were quite simple were not difficult for me.


Did you understand your errors?

I understood almost all of my errors, most of them were simply caused by careless mistakes and reading the instructions incorrectly.

What do you not understand?

I am having a bit of trouble with some of the Critter class and how the critter acts. Other than that I feel quite confident with the Gridworld material

Thursday 17 February 2011

TwisterRunner Excersise

This is my twister class.


import info.gridworld.actor.Bug;
import info.gridworld.actor.Actor;
import info.gridworld.grid.Grid;
import info.gridworld.actor.ActorWorld;
import java.awt.Color;
import java.util.ArrayList;
import info.gridworld.grid.Location;

/**
* Write a description of class Twister here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Twister extends Actor
{
 public Twister()
 {
           setColor (Color.black);
        }
  
        public void act()
        {
                destroy();
                 move ();
        }
  
        public void destroy()
       {

                 Grid<Actor> gr = getGrid();
                
                 ArrayList<Location> locs = gr.getOccupiedLocations();
                  
                 for (Location loc : locs) {
                    
                     Actor a = gr.get(loc);
                      
                     Location aLoc = a.getLocation();
                      
                     if(aLoc.getCol() == getLocation().getCol() &&
                        
                     aLoc.getRow() > getLocation().getRow()) {
                          
                         a.removeSelfFromGrid();
                        }
                    }
       }
  
       public void move()
       {

           Location next = getLocation().getAdjacentLocation(Location.EAST);
           if(Math.random() < 0.5) {
        
               next = getLocation().getAdjacentLocation(Location.WEST);
                  {
                    if(getGrid().isValid(next)) {
                      moveTo(next);
                             } else {
                                 removeSelfFromGrid();
                                }
                            }
                        }
       }
    }

Wednesday 16 February 2011

Gridworld Part III

Gridworld: Part 3: Classes & Interfaces: Set 3: Page 19




1.

Location loc1 = new Location(4, 3);
Location loc2 = new Location(3, 4);

How would you access the row value for loc1?  

2.
Location loc1 = new Location(4, 3);
Location loc2 = new Location(3, 4);

What is the value of  b  after the following statement is executed?

boolean b = loc1.equals(loc2);


3.
Location loc1 = new Location(4, 3);
Location loc2 = new Location(3, 4);

What is the value of loc3  after the following statement is executed?

Location loc3 = loc2.getAdjacentLocation(Location.SOUTH);

4.
Location loc1 = new Location(4, 3);
Location loc2 = new Location(3, 4);


What is the value of dir  after the following statement is executed?

int dir = loc1.getDirectionToward(new Location(6, 5));

5. How does the getAdjacentLocation()  method know which adjacent location to return?  


Gridworld: Part 3: Classes & Interfaces: Set 4: Page 21



1. How can you obtain a count of the objects in a grid? How can you obtain a count of the empty locations in a bounded grid?

2. How can you check if location (10,10) is in a grid?  

3. Grid contains method declarations, but no code is supplied in the methods.

Why?

Where can you find the implementations of these methods?

4. All methods that return multiple objects return them in an ArrayList.  

Do you think it would be a better design to return the objects in an array?

Explain your answer.  



Gridworld: Part 3: Classes & Interfaces: Set 5: Page 23

 




1
What methods are implemented inCritter?  

2
What are the five basic actions common to all critters when they act?  

3
Should subclasses of Critter override thegetActors()   method?

Explain

4
Describe three ways that a critter could process actors.  

5
What three methods must be invoked to make a critter move?

Explain each of  these methods.  

6
Why is there no Critter constructor?  




Gridworld: Part 3: Classes & Interfaces: Set 6: Page 25-26




1
Which statement(s) in the canMove() method ensures that a bug does not try to move out of its grid?  

2
Which statement(s) in the canMove()method determines that a bug will not walk into a rock?  

3
Which methods of the Grid  interface are invoked by the canMove()  method and why?  

4
Which method of the Location  class is invoked by the canMove() method and why?  

5
Which methods inherited from the Actor class are invoked in the canMove()method?  

6
What happens in the move() method when the location immediately in front of the bug is out of the grid?  

7
Is the variable loc needed in the move()method, or could it be avoided by callinggetLocation() multiple times?  

8
Why do you think the flowers that are dropped by a bug have the same color as the bug?  

9
When a bug removes itself from the grid, will it place a flower into its previous location?  

10
Which statement(s) in the  move() method places the flower into the grid at the bug’s previous location?  

11
If a bug needs to turn 180 degrees, how many times should it call the turn()method?  

12



Monday 14 February 2011

Barron’s Review (Inheritance & Polymorphism)

How did you do on the multiple choice questions?

I got 8 wrong on the multiple choice, most of my mistakes were on questions about abstract classes and some mistakes were about interfaces.

Did you understand your errors?

I understood most of my errors however I am not sure I am confident enough in the subject of inheritance. I am hoping to work on it more and perhaps even talk to you in class in order to improve.

What do you not understand?

I cannot state something I dont understand in particular, I am simply having a bit of trouble in the multiple choice questions about interfaces and inheritance.

GRIDWORLD PART II

Gridworld: Part 2: Bug Variations: Set 2: Page 12




1. What is the role of the instance variablesideLength?
The number input will determine the number of moves the class makes until the bug turns. 
2. What is the role of the instance variablesteps?  
count the bug steps by incrementing it every move 
3. Why is the turn() method called twice when steps becomes equal to sideLength?  
because one turn method call only turns the bug halfway and in order to make it turn completley (90 degrees) we must call it twice. 
4. Why can the move() method be called in the BoxBug class when there is no move() method in the BoxBug code?  
Since it inherits the methods from its super class which contain this method. 
5. After a BoxBug is constructed, will the size of its square pattern always be the same? Why or why not?
yes, because there is no method that changes the size of the squirrel, therefore the size will remain the same. 
6. Can the path a BoxBug travels ever change? Why or why not?  
Yes it can change,if the bug is obstructed by either a rock or the edge of the grid it will turn and change its path 
7. When will the value of steps be zero?  
I noticed it is zero right when the bug makes a turn, but there could me more options I am not sure. 


Gridworld: Part 2: Exercises: Page 13-15




1. Write a class CircleBug  that is identical to BoxBug,  except that in the act()  method the turn() method is called once instead of twice. How is its behavior different from aBoxBug?  

 public void act()
    {
        if (steps < sideLength && canMove())
        {
            move();
            steps++;
        }
        else
        {
            turn();
            turn();
            steps = 0;
        }


it doesnt make 90 degree turns, but rather 45 degree turns. As a result it creates an octagon    
2. Write a class SpiralBug  that drops flowers in a spiral pattern.

Hint: Imitate BoxBug,  but adjust the side length when the bug turns. You may want to change the world to an UnboundedGrid  to see the spiral pattern more clearly.

 public void act()
    {
        if (steps < sideLength && canMove())
        {
            move();
            steps++;
        }
        else
        {
            turn();
            turn();
            steps = 0;
            sideLength++;
        }
    }
I incremented the sidelength variable in order to form the spiral, it must increase every move to make sure that the bug does not hit its own trail of flowers and ruin flowers.
3. Write a class ZBug  to implement bugs that move in a “Z” pattern, starting in the top left corner. After completing one “Z” pattern, a ZBug  should stop moving.

In any step, if a ZBug  can’t move and is still attempting to complete its “Z” pattern, the ZBug  does not move and should not turn to start a new side. Supply the length of the “Z” as a parameter in the constructor. The following image shows a “Z” pattern of length 4.

Hint: Notice that a ZBug  needs to be facing east before beginning its “Z” pattern.  

    */
    public void act()
    {
        if (steps < sideLength && canMove())
        {
            move();
            steps++;
        }
        else
        {
            if (east)
                {
                    turn();
                    turn();
                    turn();
                    steps = 0;
                    east = false;
                }
            else
                {
                    turn();
                    turn();
                    turn();
                    turn();
                    turn();
                    steps = 0;
                    east = true;
I altered the act method in order to make sure the bug makes the correct number of moves to form the perfect Z. im awesome
4. Write a class DancingBug  that “dances” by making different turns before each move. The DancingBug  constructor has an integer array as parameter. The integer entries in the array represent how many times the bug turns before it moves.

For example, an array entry of 5 represents a turn of 225 degrees (recall one turn is 45 degrees). When a dancing bug acts, it should turn the number of times given by the current array entry, then act like a Bug.  In the next move, it should use the next entry in the array. After carrying out the last turn in the array, it should start again with the initial array value so that the dancing bug continually repeats the same turning pattern.

The DancingBugRunner  class should create an array and pass it as a parameter to the DancingBug  constructor.
?
5. Study the code for the BoxBugRunner  class. Summarize the steps you would use to add another BoxBug  actor to the grid.  
You would create a method that works by clicking on an empty cell
The method will consruct a bug and its parameters will be the sidelength variable