
/**
 * A Car, which includes a descriptor and value.
 *
 * @author Zach Tomaszewski
 * @version Sep 12, 2007
 */
public class Car {

  private String descriptor;
  private int value;


  /**
   * Constructs a new Car with the given parameters.
   *
   * @param desc  A brief descriptor, such as color or model.
   * @param val   A whole-dollar value for this car.
   */
  public Car(String desc, int val) {
    this.descriptor = desc;
    this.value = val;
  }


  /**
   * Crashes this car into the given target car.
   * This car's value drops by 10%, while the target
   * car's value is halved.
   */
  public void crashInto(Car target) {
    target.value = target.value / 2;
    this.value = (this.value * 9)/10; //only 90% value left
  }

  /**
   * Returns this car's current value.
   */
  public int getValue() {
    return this.value;
  }

  /**
   * Repairs this car, which increases its value by the
   * given amount.
   */
  public void repair(int valueIncrease) {
    this.value = this.value + valueIncrease;
  }


  /**
   * Returns a string representation of this car, which
   * includes only "<i>descriptor</i> car".
   */
  public String toString() {
    return this.descriptor + " car";
  }


  public static void main(String[] args) {
    Car first = new Car("red", 500);
    Car second = new Car("blue", 1000);

    System.out.println("Two new cars and their values:");
    System.out.println(first + ": $" + first.getValue());
    System.out.println(second + ": $" + second.getValue());

    System.out.println();
    System.out.println("After the " + first + " smashes into the " +
                        second + ":");
    first.crashInto(second);
    System.out.println(first + ": $" + first.getValue());
    System.out.println(second + ": $" + second.getValue());

  }

}
