
/**
 * Car lab solution - Part 1
 * @author Nancy Harris, James Madison University
 * @version V1
 */
public class Car 
{
	public final int MAX_SPEED = 150;
	
	private int year;
	private String model;
	private int speed;
	
	
	/**
	 * Constructor for the Car
	 * @param year The model year
	 * @param model The particular model of the car
	 */
	public Car (int year, String model)
	{
		this.year = year;
		this.model = model;
		this.speed = 0;
	}
	
	/**
	 *  Accelerate increases the car speed by 5
	 */
	public void accelerate()
	{
		this.speed = this.speed + 5;
		if (this.speed > MAX_SPEED)
			this.speed = MAX_SPEED;
	}
	
	/**
	 * Accelerate increases the car speed by the amount
	 * @param amount amount to increase the speed
	 */
	public void accelerate(int amount)
	{
		this.speed = this.speed + amount;
		if (this.speed > MAX_SPEED)
			this.speed = MAX_SPEED;
	}
	
	/**
	 *  Brake reduces the car speed by 5
	 */
	public void brake()
	{
		this.speed = this.speed - 5;
		
		if (this.speed < 0)
			this.speed = 0;
	}
	
	/**
	 * Brake reduces the car speed by the amount
	 * @param amount The amount to reduce the speed
	 */
	public void brake(int amount)
	{
		this.speed = this.speed - amount;
		
		if (this.speed < 0)
			this.speed = 0;
	}
	/**
	 * crash - "crashes" two cars
	 * @param other The other car
	 */
	public void crash(Car other)
	{
		System.out.println("CRASH!!!!");
		
		this.speed = 0;
		other.speed = 0;
	}
	
	/**
	 * getModel provides the model of this car
	 * @return The model of this car
	 */
	public String getModel()
	{
		return this.model;
	}
	
	/**
	 * getSpeed gets the current speed of this car
	 * @return The current speed
	 */
	public int getSpeed()
	{
		return this.speed;
	}
	
	/**
	 * getYear gets the model year
	 * @return The model year of this car
	 */
	public int getYear()
	{
		return this.year;
	}
	
	/**
	 * toString formats the attributes to represent this car
	 * @return A string representation of this car
	 */
	public String toString()
	{
		return String.format("A %d %s that is going %d mph", 
				year, model, speed);
	}
}
