Class Bug

java.lang.Object
  extended by Bug

public class Bug
extends java.lang.Object

Bugs are simple creatures that only know how to walk towards other bugs. Bugs maintain information about their (x, y) position. Bugs can tell if they are standing next to other bugs.


Field Summary
private  int myX
           
private  int myY
           
 
Constructor Summary
Bug()
          Default constructor, initializes both private fields to 0.
Bug(int x, int y)
          Constructs a bug with initial position specified by x and y.
 
Method Summary
 int getX()
          Answers the question, "What is your x-coordinate?" Accessor method for the private field myX.
 int getY()
          Answers the question, "What is your y-coordinate?" Accessor method for the private field myY.
 boolean sameSpot(Bug arg)
          Answers the question, "Are you at the same position as arg?"
 void walkTowards(Bug arg, double percent)
          Changes this bug's position by walking some percentage of the way towards arg.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myX

private int myX

myY

private int myY
Constructor Detail

Bug

public Bug()
Default constructor, initializes both private fields to 0.


Bug

public Bug(int x,
           int y)
Constructs a bug with initial position specified by x and y.

Method Detail

getX

public int getX()
Answers the question, "What is your x-coordinate?" Accessor method for the private field myX.

Returns:
x coordinate of this bug

getY

public int getY()
Answers the question, "What is your y-coordinate?" Accessor method for the private field myY.

Returns:
y coordinate of this bug

walkTowards

public void walkTowards(Bug arg,
                        double percent)
Changes this bug's position by walking some percentage of the way towards arg. Imagine a straight line connecting this bug with arg. The method causes this bug to walk along that straight line. The distance traveled by this bug along that straight line is equal to the specified percentage of the entire length.

Parameters:
arg - bug to walk towards
percent - percent of the total distance between this bug and arg that this bug actually walks

sameSpot

public boolean sameSpot(Bug arg)
Answers the question, "Are you at the same position as arg?"

Parameters:
arg - bug whose position is compared to this bug's position
Returns:
true if this bug's (x, y) equals arg's (x, y)