// Arup Guha
// 11/7/2015
// Example of a class in Java: Car

import java.util.*;

public class Car {

	// Instance variables that comprise a Car object.
	private int fuelTankSize;
	private int mpg;
	private double currentFuel;
	private int odometer;

	// Constructor - builds a car object
	public Car(int tankSize, int fuelEff) {

		// My job is to give values to the instance variables.
		fuelTankSize = tankSize;
		mpg = fuelEff;
		currentFuel = tankSize;
		odometer = 0;
	}

	public double milesToEmpty() {
		return currentFuel*mpg;
	}

	void addFuel(double numGallons) {

		// You're trying to put in too much, we'll just give you a full tank.
		if (numGallons+currentFuel > fuelTankSize)
			currentFuel = fuelTankSize;

		// Add the gas...
		else if (numGallons > 0)
			currentFuel = currentFuel + numGallons;
	}

	public void drive(int distance) {

		double canDrive = milesToEmpty();

		// You want to drive to far...I'll make you stuck after driving
		// canDrive miles.
		if (distance > canDrive) {
			currentFuel = 0;
			odometer = odometer + (int)canDrive;
		}

		// Okay, this is reasonable.
		else if (distance > 0) {
			currentFuel = currentFuel - (double)distance/mpg;
			odometer = odometer + distance;
		}
	}

	public String toString() {
		return "Odometer: "+odometer+" Fuel Left: "+currentFuel;
	}

	public static void main(String[] args) {

		Car myPrius = new Car(12, 40);
		Car badGasGuzzler = new Car(30, 8);

		myPrius.drive(100);
		System.out.println("Here is my prius: "+myPrius);
		System.out.println("Here is the other car: "+badGasGuzzler);

		badGasGuzzler.drive(250);
		System.out.println("Here is the other car: "+badGasGuzzler);

		badGasGuzzler.addFuel(10);
		myPrius.addFuel(2);
		System.out.println("Here is my prius: "+myPrius);
		System.out.println("Here is the other car: "+badGasGuzzler);

	}
}