java.lang.Object Bug
public class Bug
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 |
---|
private int myX
private int myY
Constructor Detail |
---|
public Bug()
public Bug(int x, int y)
Method Detail |
---|
public int getX()
public int getY()
public void walkTowards(Bug arg, double percent)
arg
- bug to walk towardspercent
- percent of the total distance between this bug and arg that this bug actually walkspublic boolean sameSpot(Bug arg)
arg
- bug whose position is compared to this bug's position