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.*; import java.io.*; public class Customers { private Vector customer;; public Customers() { customer = new Vector(); try { BufferedReader fileIn = new BufferedReader( new FileReader("customers.dat")); String input; while ((input = fileIn.readLine()) !=null) { StringTokenizer st = new StringTokenizer(input, ","); 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); }//while fileIn.close(); }//try catch (Exception e) { System.out.println(e.getMessage()); } } public Customer getCustomer(String id) { for (int i = 0; i < customer.size(); i++) { Customer c = (Customer)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)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.*; import java.io.*; public class Inventory { private Vector plants;; private String[] p = {"Lilly,14.50,6,Sam", "Ivy,12.35,10,Lilly", "Tulip,17.85,3,Daisy"}; public Inventory(Vendors v) { plants = new Vector(); try { BufferedReader fileIn = new BufferedReader( new FileReader("inventory.dat")); String input; while ((input = fileIn.readLine()) !=null) { StringTokenizer st = new StringTokenizer(input, ","); 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)); }// while fileIn.close(); }//try catch (Exception e) { System.out.println(e.getMessage()); } } public Plant getPlant(String name) { for (int i = 0; i < plants.size(); i++) { Plant temp = (Plant)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" + (Plant)plants.elementAt(i); } return out; } public void addPlant(String name, double price, int onHand, Vendor vendor) { plants.addElement(new Plant(name,price,onHand,vendor)); } }//class /////////////////////////////////////NEW FILE///////////////////////////// import java.util.*; import java.text.*; import java.net.*; import java.io.*; public class Order implements Runnable { private Customer customer; private Plant plant; private Date date; private PatsUserInterface pui; private Thread thread; public Order(Customer cust, Plant pl, PatsUserInterface p) { customer = cust; plant = pl; date = new Date(); pui = p; thread = new Thread(this, "OrderThread"); thread.start(); } public void run() { int days = plant.getVendor().getAverageDelivery(); try { URL doIt = new URL("http://komar.cs.stthomas.edu/servlet/PlantInStock?plant=" + plant.getName()); BufferedReader in = new BufferedReader( new InputStreamReader( doIt.openStream())); String status = in.readLine(); if (status.equalsIgnoreCase("out")) { days = days + 2; pui.backorder(this); } } catch (Exception e) { System.out.println("Error: getting data from server"); } try { Thread.sleep(days * 1000); } catch (InterruptedException ie) { System.out.println("Error: thread interrupted"); } pui.orderDone(this); } 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, PatsUserInterface pui) { Order o = new Order(customers.getCustomer(cust), inventory.getPlant(plant), pui); orders.addElement(o); } public String toString() { String out = ""; for (int i = 0; i < orders.size(); i++) { out = out + (Order)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 = (Order)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 interface PatsUserInterface { void orderDone(Order o); void backorder(Order o); } /////////////////////////////////////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.*; import java.io.*; public class TestPat implements PatsUserInterface { private PatsPottedPlants pats; private Customers customers; private Vendors vendors; private Inventory inventory; private Orders orders; private BufferedReader keyIn; public TestPat() throws IOException { keyIn = new BufferedReader( new InputStreamReader(System.in),1); pats = new PatsPottedPlants(); customers = pats.getCustomers(); vendors = pats.getVendors(); inventory = pats.getInventory(); orders = pats.getOrders(); String choice = "1"; while (!choice.equals("5")) { System.out.println("Pats Main Menu \n\n\t1. Add a Customer\n" + "\t2. Add a Vendor \n" + "\t3. Add a Plant \n" + "\t4. Enter an Order \n" + "\t5. Quit \n\n" + "Enter the number of your choice: "); choice = keyIn.readLine(); switch (choice.charAt(0)) { case '1': addCustomer(); break; case '2': addVendor(); break; case '3': addPlant(); break; case '4': enterOrder(); break; case '5': break; default: System.out.println("Please enter a valid choice!"); break; }//switch }//while }//constructor public void orderDone(Order order) { System.out.println("\n*********** Order Delivered ******************"); System.out.println(order); } public void backorder(Order order) { System.out.println("\n************** Order Backordered *****************"); System.out.println(order.getPlant().getName()); } public void addCustomer() throws IOException { String response = "Y"; while (response.equalsIgnoreCase("y")) { System.out.println("\n******************** New Customer ******************"); String id = null; Customer cust = null; do { System.out.print("Enter the new customer ID: "); id = keyIn.readLine(); cust = customers.getCustomer(id); if (!(cust == null)) { System.out.println("Customer ID alrady in use! Reenter\n"); } }while (!(cust == null)); System.out.print("Enter the customer name: "); String name = keyIn.readLine(); System.out.print("Enter the customer location: "); String location = keyIn.readLine(); System.out.print("Enter the S for Student or E for employee (staff): "); String type = keyIn.readLine(); if (type.equalsIgnoreCase("S")) { System.out.print("Enter the Student Major Field code: "); } else { System.out.print("Enter the employee department code: "); } String mOrd = keyIn.readLine(); customers.addCustomer(type, name, id, location, mOrd); System.out.print("\nDo you want to add another customer? (Y or N) "); response = keyIn.readLine(); }//while }//addCustomer public void addVendor() throws IOException { String response = "Y"; while (response.equalsIgnoreCase("y")) { System.out.println("\n******************** New Vendor ******************"); String name = null; Vendor vend = null; do { System.out.print("Enter the new vendor name: "); name = keyIn.readLine(); vend = vendors.getVendor(name); if (!(vend == null)) { System.out.println("Vendor name alrady in use! Reenter\n"); } }while (!(vend == null)); System.out.print("Enter the vendor address: "); String address = keyIn.readLine(); System.out.print("Enter the vendor average delivery time: "); int delivery = Integer.parseInt(keyIn.readLine()); vendors.addVendor(name, address,delivery); System.out.print("\nDo you want to add another vendor? (Y or N) "); response = keyIn.readLine(); }//while }//addVendor public void addPlant() throws IOException { String response = "Y"; while (response.equalsIgnoreCase("y")) { System.out.println("\n******************** New Plant ******************"); String name = null; Plant plant = null; Vendor vend = null; do { System.out.print("Enter the new plant name: "); name = keyIn.readLine(); plant = inventory.getPlant(name); if (!(plant == null)) { System.out.println("Plant name alrady in use! Reenter\n"); } }while (!(plant == null)); do { System.out.print("Enter Vendor Name: "); String vendorName = keyIn.readLine(); vend = vendors.getVendor(vendorName); if (vend == null) { System.out.println("Vendor Name Invalid! Please reenter\n"); } }while (vend == null); System.out.print("Enter the price for the plant: "); double price = Double.parseDouble(keyIn.readLine()); System.out.print("Enter the number on hand: "); int onHand = Integer.parseInt(keyIn.readLine()); inventory.addPlant(name, price, onHand, vend); System.out.print("\nDo you want to add another plant? (Y or N) "); response = keyIn.readLine(); }//while }//addPlant public void enterOrder() throws IOException { String response = "Y"; while (response.equalsIgnoreCase("Y")) { System.out.println("*************** New Order ******************\n"); String id = null; String plantName = null; Customer cust = null; do { System.out.print("Enter the Customer ID: "); id = keyIn.readLine(); cust = customers.getCustomer(id); if (cust == null) { System.out.println("Customer ID Invalid! Please reenter\n"); } }while (cust == null); Plant plant = null; do { System.out.print("Enter Plant Name: "); plantName = keyIn.readLine(); plant = inventory.getPlant(plantName); if (plant == null) { System.out.println("Plant Name Invalid! Please reenter\n"); } }while (plant == null); orders.addOrder(id, plantName, this); System.out.print("\nDo you want place another order? (Y or N) "); response = keyIn.readLine(); }//while System.out.println("\n" + orders); }//enterOrder public static void main(String[] args) throws IOException { new TestPat(); } }//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.*; import java.io.*; 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(); try { BufferedReader fileIn = new BufferedReader( new FileReader("vendors.dat")); String input; while ((input = fileIn.readLine()) !=null) { StringTokenizer st = new StringTokenizer(input, ","); 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); }// while fileIn.close(); }//try catch (Exception e) { System.out.println(e.getMessage()); } } public Vendor getVendor(String name) { for (int i = 0; i < vendors.size(); i++) { Vendor temp = (Vendor)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