import java.lang.String;
import java.lang.Integer;
import java.lang.Float;
import java.util.Hashtable;
import java.util.Enumeration;

public class TravelCorner 
{
	protected Hashtable items = new Hashtable();

	public TravelCorner() 
	{
	}
	
	/* add a record of flight information to the travel plan corner if not exist*/

	public boolean addItem(String flightID, String departDate, String departCity, String arrivalCity,
		String departTime, String arrivalTime, int durationTime, int price) 
	{
		String dtimeStr, priceStr;

		dtimeStr = Integer.toString(durationTime);
		priceStr = Integer.toString(price);

		for(int i = dtimeStr.length(); i < 4; i++)
			dtimeStr = new String(" "+dtimeStr);
		for(int i = priceStr.length(); i < 5; i++)
			priceStr = new String(" "+priceStr);
		String[] item = {flightID, departDate, departCity, arrivalCity, departTime, arrivalTime, 
			dtimeStr, priceStr};

		boolean success;		// successfully add in or not

		String key = flightID + departDate;
	
		if (items.containsKey(key)) 
		{
			// do nothing since exist in the
			success = false; 
		}
		else 
		{
			items.put(key, item);
			success = true;
		}
		
		return success;
	}

	/* remove a record from the travel plan corner */

	public void removeItem(String flightID, String departDate) 
	{
		String key = flightID + departDate;
		if (items.containsKey(key)) 
		{
			items.remove(key);
		}
	}


	
	/* Get an Enumeration to the list of items in the travel plan corner */
	
	public Enumeration getEnumeration() 
	{
		return items.elements();
	}

	/* Get the total price from the travel plan corner */

	public int getPrice() 
	{
		Enumeration enum = items.elements();
		String[] tmpItem;
		int totalPrice = 0;
		
		while (enum.hasMoreElements()) 
		{
			tmpItem = (String[])enum.nextElement();
			totalPrice += Integer.parseInt(tmpItem[7].trim());
		}

		return totalPrice;
	}

	/* Get the total duration time */

        public int getTime()   
        {
                Enumeration enum = items.elements();
                String[] tmpItem;
                int totalTime = 0;   
                
                while (enum.hasMoreElements())  
                {
                        tmpItem = (String[])enum.nextElement();
                        totalTime += Integer.parseInt(tmpItem[6].trim()); 
                }

                return totalTime;
        }

	/* get the total number of record currently in the travel plan corner */

	public int getNumOfItems() 
	{
		return items.size();
	}
	
	/* empty the traval plan corner */
	
	public void empty()
	{
		Enumeration enum = items.elements();
		String[] item;

		while(enum.hasMoreElements())
		{
			item = (String[])enum.nextElement();
			removeItem((String)item[0], (String)item[1]);
		}
	}
}
