/** Headquarters (parent company) for the all of the stores */
public class Headquarters { 
  /** The stores owned by the parent company */
  private Store stores[];
  /** The daily sales for all stores */
  private int dailySales [] [];
  /** The daily purchases (expenses) for all stores */
  private int dailyPurchases [] [];
  /** Table containing the days of the week constant literals */
  public static final String DAYS_OF_WEEK [] 
    = {"Monday", "Tuesday", "Wednesday", "Thursdat", "Friday", 
		  "Saturday", "Sunday"};
  /** Create a headquarters using an array of Stores.  
   *  Create the arrays for daily sales and purchases. 
   */
  public Headquarters(Store s []) {
    stores = s;
    dailySales = new int [s.length] [7];
    dailyPurchases = new int [s.length] [7];
  
  }
  /** Set the sale amount for Store name, on daynumber day 
   *  to the value amount.
   * If either the name or daynumber is invalid, display
   * an error message.
   */
  public void setSales(String name, int day, int amount) {
    int i = 0;
    if (day < 1 || day > 7) {
      System.out.println ("Day is not valid");
    } else {
      while (i < stores.length && !name.equals(stores[i].getName())){
        i++;
      }
      if (i < stores.length) {
        dailySales [i] [day-1] = amount;
      } else {
           System.out.println ("Store name is not valid");
      }
    }
  }
    
  
  /** Get the sale amount for Store name, on daynumber day. 
   *  Return the value as an int.  
   * If either the name or daynumber is invalid, display
   * an error message and return -1
   */
    public int getSales(String name, int day) {
    int i = 0;
    int result = -1;
    if (day < 1 || day > 7) {
      System.out.println ("Day is not valid");
    } else {
      while (i < stores.length && !name.equals(stores[i].getName())){
        i++;
      }
      if (i < stores.length) {
        result = dailySales [i] [day-1];
      } else {
           System.out.println ("Store name is not valid");
      }
    }
    return result;
  }
    

  
  /** Set the purchase amount for Store name, on daynumber day 
   *  to the value amount.
   * If either the name or daynumber is invalid, display
   * an error message.
   */
 

  public void setPurchases(String name, int day, int amount) {
    int i = 0;
    if (day < 1 || day > 7) {
      System.out.println ("Day is not valid");
    } else {
      while (i < stores.length && !name.equals(stores[i].getName())){
        i++;
      }
      if (i < stores.length) {
        dailyPurchases [i] [day-1] = amount;
      } else {
           System.out.println ("Store name is not valid");
      }
    }
  }
    
 
  
   /** Get the purchase amount for Store name, on daynumber day. 
   *  Return the value as an int.  
   * If either the name or daynumber is invalid, display
   * an error message and return -1
   */
   
  public int getPurchases(String name, int day) {
    int i = 0;
    int result = -1;
    if (day < 1 || day > 7) {
      System.out.println ("Day is not valid");
    } else {
      while (i < stores.length && !name.equals(stores[i].getName())){
        i++;
      }
      if (i < stores.length) {
        result = dailyPurchases [i] [day-1];
      } else {
           System.out.println ("Store name is not valid");
      }
    }
    return result;
  }
    
    /** 
   * print the store activity for store sNum for the week.
   * First print the store name and manager,
   * Then, for each day of the week:
   *   print the day of the week, the sale amount and the purchase amount
   * Finally Print a total for the week.
   */
  public void printStoreActivity(int sNum) {
    int totSales = 0;
    int totPurchases = 0;
    System.out.println("Store: " + stores[sNum].getName() + 
                       " Manager: " + stores[sNum].getManager() );
    for (int i = 0; i < dailySales[sNum].length; i++) {
      System.out.println(DAYS_OF_WEEK[i] + " sales: " + dailySales[sNum][i] +
                         " purchases: " + dailyPurchases[sNum][i] );
      totSales += dailySales[sNum][i];
      totPurchases += dailyPurchases[sNum][i];
    }
    System.out.println("Total sales: " + totSales + " purchases: "  + 
                       totPurchases);
  }



}

