Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- /**
- *
- * Car Class
- *
- * Defines the instance variables and behavior for a Car
- *
- * @author Antonio Mejorado
- * @date 8-Feb-2006
- *
- */
- public class Car extends Vehicle {
- /**
- *
- * Car default constructor
- *
- * Defines zero for x and y coordinates
- *
- */
- public Car(){
- super();
- }
- /**
- *
- * Car with two parameter constructor
- *
- * Defines zero for x and y coordinates
- *
- * @param x an <code>integer</code> value for the x coordinate
- * @param y an <code>integer</code> value for the y coordinate
- *
- */
- public Car(int x, int y) {
- super(x, y);
- }
- /**
- *
- * Draw method
- *
- * draws the Car
- *
- * @param a <code>Graphics</code> object
- *
- */
- public void draw(Graphics g) {
- g.drawOval(x+25, y+25, 25, 25); //left tire
- g.drawOval(x+100, y+25, 25, 25); // right tire
- g.drawRect(x, y -25, 150, 50); // car body
- g.drawLine(x+25,y-25,x+50, y-55); // left edge window
- g.drawLine(x+50, y-55, x+100, y-55); //up edge window
- g.drawLine(x+100, y-55, x+125, y-25); // right edge window
- }
- /**
- *
- * Equals method
- *
- * Checks if the received object is equal to the invoke object
- *
- * @return a <code>boolean</code> value, true for equals false for different
- *
- */
- public boolean equals(Object obj) {
- if (obj instanceof Car) {
- Car c = (Car) obj;
- if (this.getX() == c.getX() && this.getY() == c.getY()) return true;
- }
- return false;
- }
- /**
- *
- * ToString method
- *
- * Returns the object as an String object
- *
- * @return a <code>String</code> object corresponding to the object
- *
- */
- public String toString() {
- return " [ " + getX() + "," + getY() + " ] ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement