
public class StoreApp
{
  int maxStore = 5;
  Store[] allStores = new Store[maxStore];
  int numOfStores = 0;
  
  public int menu(){
    System.out.println("1) Create a new Store");
    System.out.println("2) Add an employee to an existing store");
    System.out.println("3) Display all employees in a particular store");
    System.out.println("4) Display information of all the stores created");
    System.out.println("5) Display all employee with a particular first name");
    System.out.println("6) Quit the system.");
    int choice = Input.readInt("Enter your choice");
    return choice;
  } // menu
  public void createNewStore(){
    String storeName = Input.readString("Store Name");
    int maxEmployees = Input.readInt("Maximum Employees");
    float storeRev = Input.readFloat("Store Revenue");
    allStores[numOfStores] = new Store(storeName, maxEmployees, storeRev);
    numOfStores ++;
  }// createNewStore
  public void showAllStores(){
    for (int i=0; i < numOfStores; i++)
      System.out.println(i+")"+allStores[i].getName());
  }//showAllStores
  public int chooseStore(){
    showAllStores();
    int choice = -1;
    while (choice <= -1 || choice >= numOfStores) {
      choice = Input.readInt("Choose a store");
    }
    return choice; 
  }//chooseStore
  public void addEmployee() {

    if (numOfStores > 0){
      int choice= chooseStore();
      String firstName = Input.readString("First name");
      String lastName = Input.readString("Last name");
      double salary = Input.readDouble("Salary");
      int eNo = allStores[choice].addEmployee(firstName, lastName, salary);
      if (eNo != -1)
        System.out.println("Employee is added successfully.");
      else
        System.out.println("Employee can be NOT added to the store!");
    }
    else
      System.out.println("No store has been created!");

  } //addEmployee
  public void showEmployee() {
    if (numOfStores > 0){
      int choice= chooseStore();
      for (int i = 0; i < allStores[choice].getNumOfEmployees(); i++)
        System.out.println(allStores[choice].getEmployeeInfo(i));
    }
    else
      System.out.println("No store has been created!");

  } //showEmployee
  public void showAllStoresInfo(){
    for (int i=0; i < numOfStores; i++)
      System.out.println(i+")"+allStores[i]);
  }//showAllStoresINfo
  public void findEmployee(){
    String findName = Input.readString("First name");
    if (numOfStores > 0){
      for (int s = 0; s < numOfStores; s++)
        for (int i = 0; i < allStores[s].getNumOfEmployees(); i++)
          if (allStores[s].getEmployeeFirstName(i).equalsIgnoreCase(findName)){
            System.out.println(allStores[s]);
            System.out.println(allStores[s].getEmployeeInfo(i));
          } // if allStores
    }//if numOdStore
    else
      System.out.println("No store has been created!");

  }//findEmployee
  public void run(){
    int choice = 0;
    while (choice !=6) {
      choice = menu();
      switch(choice) {
        case 1:
          createNewStore();
          break;
        case 2:
          addEmployee();
          break;
        case 3:
          showEmployee();
          break;
        case 4:
          showAllStoresInfo();
          break;
        case 5:
          findEmployee();
          break;
	case 6:
          break;
	default:
	  System.out.println("Invalid choice");
      } // switch
    } // while
  } // run
  public static void main (String[] args) 
  {
    StoreApp myApp = new StoreApp();
    myApp.run();
  } // main
} // StoreApp


