/* * Cab.java * * Skeleton Cab class used by Taxicab Dispatcher Applet * * Created by implementing the full Cab class * for HW1 and then deleting much of it. This is no * longer guaranteed to compile! * */ class Cab { // Define the max X & Y coordinates/locations of a cab. public static final int XMIN = 20; public static final int XMAX = 500; public static final int YMIN = 20; public static final int YMAX = 400; // The following define the width & height in pixels of the // rectangle that represents the cab. public static final int CABWIDTH = 50; public static final int CABHEIGHT = 25; private String name = ""; // The cab's label, always displayed with it private String dropoff = ""; // If state = STATE_DROP, // this is the address where customer is going. private String pickup = ""; // If state = STATE_PICKUP, // this is the address where cab will pickup customer. // Define the rectange that is the graphic representation of the cab. // We make it public so we can directly use its methods rather than // having to define wrapper Cab class methods. Its height, width, & x & y // coordinates define the shape & position of the cab in the display. // However, the Cab setX, setY methods should be used rather than the // rectangle's, since the Cab methods can enforce the X & Y limits. public Rectangle rectangle = null; // Constructor - sets name (which can only be set on creation), initial state, // and start location public Cab (String cabName, int initState, int initX, int initY) { name = cabName; state = initState; rectangle = new Rectangle (initX, initY, CABWIDTH, CABHEIGHT); } void setState(int newState) { state = newState; } int getState() { return state; } String getName() { return name; } void setDestination(String dest) { destination = dest; } String getDestination() { return destination; } void setPickup(String dest) { pickup = dest; } String getPickup() { return pickup; } void setXLoc(int xloc) { if (xloc < XMIN) { rectangle.x = XMIN; } else if (xloc > XMAX) { rectangle.x = XMAX; } else { rectangle.x = xloc; } } int getXLoc() { return rectangle.x; } void setYLoc(int yloc) { if (yloc < YMIN) { rectangle.y = YMIN; } else if (yloc > YMAX) { rectangle.y = YMAX; } else { rectangle.y = yloc; } } int getYLoc() { return rectangle.y; }