SE-1011 Software Development 1
Lab 8: Gobots!

Outcomes

Assignment

Christmas is only a few months away, and I had a bright idea for a toy that will be this year's hot item: a Gobot. A Gobot is a robotic vehicle (I made up this catchy name) that can be programmed to move (that is, "go") in different directions (N, S, E, W) at a given speed for a specified period of time.

Your assignment is to write the Java class that defines the attributes and behaviors of a Gobot, according to the following UML class diagram:

Our Gobot has a number of attributes, both instance and class. The meaning of the name attribute is obvious, right? The batteryLevel attribute represents the amount of charge the Gobot contains when it is created - Gobots can't be recharged; when they run out of charge, they stop working. The distanceTraveled attribute keeps track of how far the Gobot has gone in its life. The x and y attributes keep track of where the Gobot is at any point. The speed attribute controls how fast the Gobot moves from one point to another. The color attribute indicates the color of the line that the Gobot uses to plot its location - read the next paragraph for an explanation of plotting.

Gobots plot their coordinates when they are told to move somewhere. To plot, a Gobot uses a WinPlotter. The WinPlotter object is not created by the Gobot; instead, a WinPlotter object is created externally and a WinPlotter reference is given to the Gobot to use via the Gobot constructor. Every Gobot uses the same WinPlotter, so the plotter attribute is static.

To construct a Gobot, you need to invoke it's constructor with 4 arguments: the Gobot's name, its initial charge, the Color to be used during plotting (see java.awt.Color), and the reference to a WinPlotter that it will use for plotting.

A Gobot won't move unless you set it's speed to some finite value, because the constructor sets the speed attribute to 0. The setSpeed() Mutator is used for this purpose.

The move() method is what makes a Gobot move. This method takes two arguments: the direction in which to move, and the duration of the move. The distance moved is computed automatically within the move() method via the physics formula d = vt, where v is the speed and t is the time duration of the move. The Gobot uses up part of its charge whenever it moves, according to the formula e=fv2t, where e is the energy (battery level) used, and f is the drag coefficient. Before the move() method executes the specified move, it checks first, via a call to the private method canMove(), to see if it can actually perform the move. If not, too bad - the Gobot is dead (time to buy more!) and it outputs an 'X' in the plot at it's current x,y coordinates.

You can read more about the Gobot's methods in this javadoc.

Detailed requirements

You must write the Gobot class, to be in a package named msoe.se1011.<your msoe email name>.

Test your Gobot by using this RobotProgram.java driver. Your program can be considered "correct" if the following output is displayed in the console, and the plot below is drawn:

r2d2's battery died in iteration    4 
wallE's battery died in iteration   33 

Gobot R2D2 status
x position: 0.0
y position: 90.0
total distance traveled: 930.0
battery level: 7

Gobot Wall-E status
x position: -86.0
y position: -86.0
total distance traveled: 6956.0
battery level: 0

Lab Submission (due date in WebCT)

Submit your assignment following these instructions:

  1. You do not need to hand in a flowchart, but you may find it helpful to create one before you start coding.
  2. Upload your Gobot.java file through WebCT (assignment "Lab 8: Gobots!").
Be sure to keep copies of all your java files, in case something gets lost.

Your grade will be based on the following criteria: