/* * * Solution to In-class Assignment #1: Design of Oaks Mall * */ import java.lang.reflect.Array; import java.util.Comparator; class P2{ public static void main(String[] args){ double minWage = 6.00D; boolean t = true; boolean f = false; MallEmployee john = new MallEmployee("John", 30.0D, "morning","Mon.-Thurs.", t); MallEmployee sarah = new MallEmployee("Sarah", 20.0D, "night", "Tues.-Fri.", f); MallEmployee[] hallEmps = {john, sarah}; StoreEmployee jeff = new StoreEmployee("manager", "Jeff", 50.00D, 40.00D, "day", 7, "Mon.-Fri.", t); StoreEmployee lisa = new StoreEmployee("clerk", "Lisa", 10.00D, 30.00D, "night", 5, "Fri.-Mon.", f); StoreEmployee[] gapEmps = new StoreEmployee[100]; gapEmps[0] = lisa; Stores hall = new Stores(); Stores gap = new Stores("clothing", "GAP", t, gapEmps, 500, 15.00D, 1000.00D, 1, "shirts"); Stores bb = new Stores("electronics", "Best Buy", t, gapEmps, 500, 15.00D, 1000.00D, 1, "computers"); Customers orli = new Customers("Orli", 100.00D); Customers dan = new Customers("Dan", 50.00D); Customers anna = new Customers("Anna", 75.00D); Customers[] none = new Customers[1000]; Oaks mall1 = new Oaks(); //test customer actions etc... mall1.enterCustomer(anna); mall1.enterCustomer(dan); //creates store: gap --should create gap in 1st position not 0th position mall1.createStore(gap); System.out.println("Customer is Entered and Gap is created"); //check moveTo //move from hall (store[0] to store[1]) anna.moveTo(gap); System.out.println(anna.toString()); //prints the customers in gap gap.printCustomersInStore(); //prints the customers in the hall mall1.stores[0].printCustomersInStore(); //enter the customer orli mall1.enterCustomer(orli); orli.moveTo(gap); gap.printCustomersInStore(); System.out.println(orli.toString()); //now orli buys stuff gap orli.buy(gap, 3); System.out.println(orli.toString()); dan.moveTo(gap); gap.printCustomersInStore(); gap.hireEmp(jeff); gap.printEmployeesOfStore(); gap.printEmployeesOfStore(); mall1.createStore(bb); dan.moveTo(bb); gap.printCustomersInStore(); bb.printCustomersInStore(); System.out.println(""); System.out.println(""); mall1.exitCustomer(anna); mall1.stores[0].printCustomersInStore(); gap.printCustomersInStore(); bb.printCustomersInStore(); System.out.println(""); mall1.close(); System.out.println("the mall is now closed"); gap.printCustomersInStore(); bb.printCustomersInStore(); //open up the mall mall1.open(); mall1.open(); } } /******************************************************************************/ class Oaks{ public Stores[] stores = new Stores[100]; //This is the max. # of stores that can be in the mall public MallEmployee[] mallEmps = new MallEmployee[100]; //This is the max. # of mall employees that can work for the mall public Customers[] customers = new Customers[1000]; //This is the max. # of customers that can be in the entire mall int numStores; int numMallEmp; int numCustomers; boolean open; //Constructors public Oaks(){ //This creates a new object from scratch (the default) stores[0] = new Stores(); //This creates only the hallway numStores = 1; numMallEmp = 0; numCustomers = 0; open = true; } public Oaks(MallEmployee[] mallEmps, int nME, Customers[] customers, int nC){ //This is from the start of the day, without any stores numMallEmp = nME; numCustomers = nC; stores[0] = new Stores(); this.mallEmps = mallEmps; this.customers = customers; numStores = 1; open = true; } public Oaks(Stores[] stores, int nS, MallEmployee[] mallEmps, int nME, Customers[] customers, int nC){ //This is from the middle of the day, with a specified amount of stores, employees, and customers numStores = nS; numMallEmp = nME; numCustomers = nC; this.stores = stores; this.mallEmps = mallEmps; this.customers = customers; open = true; } //Open / Close Methods public void open(){ if(open == false){ open = true; //opens each store for(int i=0; i= 0)){ newCustomer.setPosition(stores[0]); //sets the customers position to 0 in the array (hall) //add this customer to the customer array in the mall customers[numCustomers] = newCustomer; numCustomers++; } else{ System.out.println(newCustomer.getName()+" cannot enter the mall because the mall already has 1000 customers inside."); } } //finds the customer index in the overal mall customer array public int findCustomerIndex(Customers someCustomer){ int customerIndex = -1; for(int j=0; j<1000; j++){ //Searches for the index of the employee if(someCustomer.equals(customers[j])){ return j; } } return -1; } //removes the customer from the mall customers array public void exitCustomer(Customers exitCustomer){ int indexOfCustomer = findCustomerIndex(exitCustomer); if(indexOfCustomer >= 0){ exitCustomer.getPosition().removeCustomer(exitCustomer); //exits from store as well while(indexOfCustomer < 1000){ if(indexOfCustomer!=999){ customers[indexOfCustomer] = customers[indexOfCustomer + 1]; } indexOfCustomer++; } numCustomers--; } else{ System.out.println(exitCustomer.getName()+" cannot exit because he/she in not in the mall."); } } public int findStoreIndex(Stores somestore){ //Searches for the index of the employee int storeIndex = -1; for(int j=0; j<100; j++){ if(somestore.equals(stores[j])){ //equals method must be made in StoreEmployee -- implements comparable return j; } } return -1; //not found } public String toString() { String x = ""; for(int i=0; i=0; i--){ removeCustomer(custs[i]); } } } //Store Status method public boolean getStatus(){ return open; //Returns the boolean value of the store } //These 2 methods are like accesor methods //Accessor Methods - I did not put in any setMethods yet public String getName(){ return name; } public String getType(){ return typeStore; } public double getPrice(){ return price; } public double getMoney(){ return money; } public int getNumItems(){ return numItems; } public void setNumItems(int num){ numItems = num; } public String getStoreItem(){ return storeItem; } //Hire Employee Methods public void hireEmp(StoreEmployee storeEmply){ try{ System.out.println("numstore emp" + numOfStoreEmployees); emps[numOfStoreEmployees] = storeEmply; numOfStoreEmployees++; //Increments the Employee counter by 1 } catch (ArrayIndexOutOfBoundsException e){ System.out.println(storeEmply.getName()+" cannot be hired because there are 100 employees already working at "+name); System.out.println(numOfStoreEmployees); } } public int findEmpIndex(StoreEmployee storeEmply){ //Searches for the index of the employee int employeeIndex = -1; for(int j=0; j<100; j++){ if(storeEmply.equals(emps[j])){ //equals method is implemented (Comparator) return j; } } return -1; //not found } //these are called by a method in Customer if a customer changes position public void addCustomer(Customers customer){ try{ custs[numOfStoreCustomers] = customer; numOfStoreCustomers++; } catch (ArrayIndexOutOfBoundsException e){ System.out.println(customer.getName()+" cannot go into the store because "+name+" already has 500 customers."); } } public int findCustomerIndex(Customers customer1){ int customerIndex = -1; for(int j=0; j<500; j++){ //Searches for the index of the customer if(customer1.equals(custs[j])){ return j; } } return -1; } public void removeCustomer(Customers customer){ int indexOfCustomer = findCustomerIndex(customer); if(indexOfCustomer >= 0){ while(indexOfCustomer < 500){ if(indexOfCustomer!=499){ custs[indexOfCustomer] = custs[indexOfCustomer + 1]; } else { //custs[indexOfCustomer] = null; } indexOfCustomer++; } numOfStoreCustomers--; } else{ // System.out.println(customer.getName()+" cannot be removed because he/she in not in "+name+"."); } } //prints the number of customers, and their names (along with their indices) public void printCustomersInStore(){ System.out.println("Customers array in the Stores class for "+getName()); //Value for numOfStoreCustomers System.out.println("There are/is "+numOfStoreCustomers+" customer(s) in this store."); for(int b=0; b=payment)&&(stuffCounter<100)){ //decrease customers money money = (money - payment); setStuff(itemName, atStore.getName(), quantity); //subtract the quantity from the store's inventory atStore.setNumItems(itemAmount-quantity); } } else{ System.out.println(name+" cannot buy "+itemName); } } public void moveTo(Stores nextStore){ this.position.removeCustomer(this); this.setPosition(nextStore); //This should call the method under the Stores class. nextStore.addCustomer(this); } public String toString(){ String x =""; String y = ""; x = "Customer: " + getName() + "\n" + "Money: " + getMoney() + "\n" + "Position: " + position.getName() + "\n"; for(int i=0; i