/**
 * a shop that sells air
 */
public class AirFillShop {
  
  /**
   * name of this shop
   */
  private String name;
  
  /**
   * how much has all shops have earned
   */
  private static double income= 0;
  
  /**
   * how much we charge (never less than $1/litre)
   */
  private double pricePerLitre;
  
  /**
   * Create an AirFillShop called name that charges
   * ppl per litre.
   */
  public AirFillShop(double ppl, String name) {
    pricePerLitre= ppl;
    this.name= name;
  }
  
  /**
   * Create an AirFillShop whose name and price
   * are contained in String pN
   */
  public AirFillShop(String pN) {
    int comma= pN.indexOf(',');
    String price= pN.substring(0,comma);
    pricePerLitre= Double.parseDouble(price);
    String nm= pN.substring(comma+2,
                            pN.length());
    name= nm;
  }
  
  /**
   * return the number of litres (rounded down)
   * that amount will buy.  Increment income by
   * amount.
   */
  public int sellAir(double amount) {
    income += amount;
    return (int) (amount/pricePerLitre);
  }
  
  /**
   * this shop's name
   */
  public String getName() {
    return name;
  }
  
  /**
   * return how many millilitres per dollar
   * we sell.
   */
  public double getMLPerDollar() {
    return 1000.0/pricePerLitre;
  }
  
  /**
   * The name and price of this shop
   */
  public String toString() {
    String result= name + ": ";
    result += getMLPerDollar();
    result += " millilitres per dollar.";
    return result;
  }
  
  /**
   * How much have all the air fill shops made
   */
  public static double getTotalIncome() {
    return income;
  }
}
