// Arup Guha
// 10/16/2026
// Car class for COP 3330 Exam 2

public class Car {

	protected double tankSize;
	protected double galGasLeft;
	protected double mpg;
	protected double odometer;
	protected double expenses;
	
	public Car(double myTankSize, double myMPG) {
		tankSize = myTankSize;
		galGasLeft = tankSize;
		mpg = myMPG;
		odometer = 0;
		expenses = 0;
	}
	
	// Question 2 Solution
	public double fillGas(double numGals, double costPerGal) {
		
		// Compute the actual number of gallons that can be added.
		double add = Math.min(numGals, tankSize-galGasLeft);
		
		// Update the expenses for gas.
		expenses += (add*costPerGal);
		
		// Update the amount of gas in the tank, and return added gas.
		galGasLeft += add;
		return add;
	}
	
	// Question 3 Solution
	public double drive(double miles) {
		
		// Get distance actually driven; can't go past empty.
		double ret = Math.min(miles, galGasLeft*mpg);
		
		// Update amount of gas left.
		galGasLeft -= (ret/mpg);
		
		// Change odometer and return miles driven.
		odometer += ret;
		return ret;
	}
	
	// Question 4 solution.
	public void park(double hours, double costPerHour) {
		
		// Everyone can agree parking sucks! Update the expenses.
		expenses += (hours*costPerHour);
	}
	
	public String toString() {
		return "["+tankSize+", "+galGasLeft+", "+mpg+", "+odometer+", "+expenses+"]";
	}
}