Advertisement
Fhernd

Car.java

Aug 10th, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. import java.awt.*;
  2.  
  3. /**
  4.  *
  5.  * Car Class
  6.  *
  7.  * Defines the instance variables and behavior for a Car
  8.  *
  9.  * @author Antonio Mejorado
  10.  * @date 8-Feb-2006
  11.  *
  12.  */
  13. public class Car extends Vehicle {
  14.    
  15.     /**
  16.      *
  17.      * Car default constructor
  18.      *
  19.      * Defines zero for x and y coordinates
  20.      *
  21.      */
  22.     public Car(){
  23.         super();
  24.     }
  25.  
  26.     /**
  27.      *
  28.      * Car with two parameter constructor
  29.      *
  30.      * Defines zero for x and y coordinates
  31.      *
  32.      * @param x an <code>integer</code> value for the x coordinate
  33.      * @param y an <code>integer</code> value for the y coordinate
  34.      *
  35.      */
  36.     public Car(int x, int y) {
  37.         super(x, y);
  38.     }
  39.    
  40.  
  41.     /**
  42.      *
  43.      * Draw method
  44.      *
  45.      * draws the Car
  46.      *
  47.      * @param a <code>Graphics</code> object
  48.      *
  49.      */
  50.     public void draw(Graphics g) {
  51.         g.drawOval(x+25, y+25, 25, 25); //left tire
  52.         g.drawOval(x+100, y+25, 25, 25); // right tire
  53.         g.drawRect(x, y -25, 150, 50); // car body
  54.         g.drawLine(x+25,y-25,x+50, y-55); // left edge window
  55.         g.drawLine(x+50, y-55, x+100, y-55); //up edge window
  56.         g.drawLine(x+100, y-55, x+125, y-25); // right edge window
  57.     }
  58.    
  59.     /**
  60.      *
  61.      * Equals method
  62.      *
  63.      * Checks if the received object is equal to the invoke object
  64.      *
  65.      * @return a <code>boolean</code> value, true for equals false for different
  66.      *
  67.      */
  68.     public boolean equals(Object obj) {
  69.         if (obj instanceof Car) {
  70.             Car c = (Car) obj;
  71.             if (this.getX() == c.getX() && this.getY() == c.getY()) return true;
  72.         }
  73.         return false;
  74.     }
  75.    
  76.     /**
  77.      *
  78.      * ToString method
  79.      *
  80.      * Returns the object as an String object
  81.      *
  82.      * @return a <code>String</code> object corresponding to the object
  83.      *
  84.      */
  85.     public String toString() {
  86.         return " [ " + getX() + "," + getY() + " ] ";
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement