public class Customer { protected String name; protected String ID; protected String location; public Customer(String n, String i, String l) { setName(n); setID(i); setLocation(l); } public void setName(String n) { name = n; } public void setID(String i) { ID = i; } public void setLocation(String l) { location = l; } public String getName() { return name; } public String getID() { return ID; } public String getLocation() { return location; } public String toString() { return "Name: " + name + "\n" + "ID: " + ID + "\n"; } }//class ////////////////////////////// NEW FILE ////////////////////////////////// import java.util.*; public class Customers { private Vector customer;; private String[] s = {"S,John,1111,200 Dowling,QMCS", "E,Jane,2222,OSS 402,CHEM", "S,Elmer,3333,300 Dowling,ENGL"}; public Customers() { customer = new Vector(); for ( int i = 0; i < s.length; i++) { StringTokenizer st = new StringTokenizer(s[i], ","); String type = new String(st.nextToken()); String name = new String(st.nextToken()); String id = new String(st.nextToken()); String location = new String(st.nextToken()); String mOrD = new String(st.nextToken()); Customer temp = null; if (type.equals("S")) { temp = new Student(name,id,location,mOrD); } else { temp = new Staff(name,id,location,mOrD); } customer.addElement(temp); }//for } public Customer getCustomer(String id) { for (int i = 0; i < customer.size(); i++) { Customer c = customer.elementAt(i); if (id.equals(c.getID())) { return c; } } return null; } public String toString() { String out = ""; for (int i = 0; i < customer.size(); i++) { out = out + "\n" + (customer.elementAt(i)).toString(); } return out; } public void addCustomer(String type,String name,String id, String location,String mOrD) { Customer temp = null; if (type.equals("S")) { temp = new Student(name,id,location,mOrD); } else { temp = new Staff(name,id,location,mOrD); } customer.addElement(temp); } }//CLASS //////////////////////////////////// NEW FILE //////////////////////////////////// import java.util.*; public class Inventory { private Vector plants; private Vendors vendors; private String[] p = {"Lilly,14.50,6,Sam", "Ivy,12.35,10,Lilly", "Tulip,17.85,3,Daisy"}; public Inventory(Vendors v) { vendors = v; plants = new Vector(); for (int i = 0; i < p.length;i++) { StringTokenizer st = new StringTokenizer(p[i], ","); String name = st.nextToken(); double price = Double.parseDouble(st.nextToken()); int days = Integer.parseInt(st.nextToken()); Vendor vend = v.getVendor(st.nextToken()); plants.addElement(new Plant(name,price,days,vend)); }//for } public Plant getPlant(String name) { for (int i = 0; i < plants.size(); i++) { Plant temp = plants.elementAt(i); if (name.equals(temp.getName())) { return temp; } } return null; } public String toString() { String out = ""; for (int i = 0; i < plants.size(); i++) { out = out + "\n" + plants.elementAt(i); } return out; } public void addPlant(String name, double price, int days, String vendorName) { plants.addElement(new Plant(name,price,days,vendors.getVendor(vendorName))); } }//class //////////////////////////////////////// NEW FILE ///////////////////////////// import java.util.*; import java.text.*; public class Order { private Customer customer; private Plant plant; private Date date; public Order(Customer cust, Plant pl) { customer = cust; plant = pl; date = new Date(); } public String toString() { DateFormat form = DateFormat.getDateInstance(); String out = "Customer Order Date: " + form.format(date) + "\n" + customer + "\n" + plant; return out; } public Customer getCustomer() {return customer;} public Plant getPlant() {return plant;} public Date getDate() {return date;} } ////////////////////////////////////// NEW FILE /////////////////////////////////// import java.util.*; public class Orders { private Vector orders = null; private Customers customers; private Inventory inventory; public Orders(Customers cust, Inventory inv) { orders = new Vector(); customers = cust; inventory = inv; } public void addOrder(String cust, String plant) { Order o = new Order(customers.getCustomer(cust), inventory.getPlant(plant)); orders.addElement(o); } public String toString() { String out = ""; for (int i = 0; i < orders.size(); i++) { out = out + orders.elementAt(i) + "\n"; } return out; } public Vector getOrders(Customer cust) { Vector temp = new Vector(); for (int i = 0; i < orders.size(); i++) { Order temp2 = orders.elementAt(i); if ((temp2.getCustomer().getID()).equals(cust.getID())) {temp.addElement(temp2);} } return temp; } }//class //////////////////////////////// NEW FILE /////////////////////////////////// public class PatsPottedPlants { private Vendors vendors; private Inventory inventory; private Customers customers; private Orders orders; public PatsPottedPlants() { vendors = new Vendors(); inventory = new Inventory(vendors); customers = new Customers(); orders = new Orders(customers, inventory); } public Vendors getVendors() { return vendors; } public Inventory getInventory() { return inventory; } public Customers getCustomers() { return customers; } public Orders getOrders() { return orders; } }//class ///////////////////////////////// NEW FILE ///////////////////////////////// public class Plant { private String name; private double price; private int numberOnHand; private Vendor vendor; public Plant(String n, double p, int num, Vendor v) { setName(n); setPrice(p); setNumberOnHand(num); setVendor(v); } public void setName(String n) { name = n; } public void setPrice(double p) { price = p; } public void setNumberOnHand(int n) { numberOnHand = n; } public void setVendor(Vendor v) { vendor = v; } public String getName() { return name; } public double getPrice() { return price; } public int getNumberOnHand() { return numberOnHand; } public Vendor getVendor() { return vendor; } public String toString() { return "Plant Name: " + name + "\n" + "Price: " + price + "\n" + "Number on hand: " + numberOnHand + "\n" + vendor + "\n"; } }//class //////////////////////////////// NEW FILE ///////////////////////////////// public class Staff extends Customer { private String department; public Staff(String n, String i, String l, String d) { super(n, i, l); setDepartment(d); } public void setDepartment(String d) { department = d; } public String getDepartment() { return department; } public String toString() { return super.toString() + "Department: " + department + "\n"; } }//class ////////////////////////////////////// NEW FILE ///////////////////////////// public class Student extends Customer { private String major; public Student(String n, String i, String l, String m) { super(n, i, l); setMajor(m); } public void setMajor(String m) { major = m; } public String getMajor() { return major; } public String toString() { return super.toString() + "Major: " + major + "\n"; } }//class /////////////////////////////// NEW FILE /////////////////////////////////////////// import java.util.*; public class TestPat { public static void main(String[] args) { PatsPottedPlants pats = new PatsPottedPlants(); Customers custs = pats.getCustomers(); Vendors vendors = pats.getVendors(); Inventory inventory = pats.getInventory(); Orders orders = pats.getOrders(); inventory.addPlant("Poison Ivy", 18.5, 2,"Sam"); System.out.println("************* Plants ******************"); System.out.println(inventory); custs.addCustomer("E", "Edgar", "5555", "403 OSS", "QMCS"); System.out.println("************* Customers ******************"); System.out.println(custs); vendors.addVendor("Joe","Way above",15); System.out.println("************* Vendors ******************"); System.out.println(vendors); orders.addOrder("1111", "Ivy"); orders.addOrder("2222", "Lilly"); orders.addOrder("2222", "Ivy"); System.out.println("************* All orders *********************"); System.out.println(orders); Vector temp = orders.getOrders(custs.getCustomer("2222")); System.out.println("**************Orders for customer 2222 **************"); for (int i = 0; i < temp.size(); i++) { System.out.println(temp.elementAt(i)); } } }//class ///////////////////////////////////// NEW FILE //////////////////////////////////////// public class Vendor { private String name; private String address; private int averageDelivery; public Vendor(String n, String a, int ad) { setName(n); setAddress(a); setAverageDelivery(ad); } public void setName(String n) { name = n; } public void setAddress(String a) { address = a; } public void setAverageDelivery(int ad) { averageDelivery = ad; } public String getName() { return name; } public String getAddress() { return address; } public int getAverageDelivery() { return averageDelivery; } public String toString() { return "Vendor name: " + name + "\n" + "Address: " + address + "\n" + "Average Delivery in days: " + averageDelivery + "\n"; } }//class /////////////////////////////// NEW FILE //////////////////////////////////// import java.util.*; public class Vendors { private Vector vendors;; private String[] v = {"Sam,Over there,2", "Lilly,Beyond there,3", "Daisy,Way far,5"}; public Vendors() { vendors = new Vector(); for ( int i = 0; i < v.length; i++) { StringTokenizer st = new StringTokenizer(v[i], ","); String name = new String(st.nextToken()); String location = new String(st.nextToken()); int days = Integer.parseInt(st.nextToken()); Vendor vend = new Vendor(name,location,days); vendors.addElement(vend); }// for } public Vendor getVendor(String name) { for (int i = 0; i < vendors.size(); i++) { Vendor temp = vendors.elementAt(i); if (name.equals(temp.getName())) { return temp; } } return null; } public String toString() { String out = ""; for (int i = 0; i < vendors.size(); i++) { out = out + "\n" + vendors.elementAt(i); } return out; } public void addVendor(String name, String location, int days) { vendors.addElement(new Vendor(name,location,days)); } }//class