QMCS 281
Pat’s Potted Plants
There will be three major tasks to accomplish for this assignment. The first is adding threading, the second is adding some networking, and the third is to add functionality to the user interface. It is strongly recommended that you complete each of these tasks one at a time before moving on to the next.
I. Threads. We will simulate the delivery of the plant ordered by changing the Order class as follows:
-- Implement the Runnable interface in the class declaration.
-- Declare a new class variable of type Thread.
-- In the constructor, instantiate the Thread object and pass it “this” to establish the order as a Thread. The last thing the constructor needs to do is have the Thread object call the start() method.
-- Write the run() method. This method should get the delivery days from the Vendor object by way of the Plant object that is a part of the order. Use that value times 1000 to put the thread to sleep. Remember that you need to have the sleep call in a try…catch structure. After the thread wakes up, the “orderDone” method of the PatsUserInterface object should be called passing the current object to that method. That should be all you need to do to simulate delivery of the plant.
II. Networking. Your program will get a message from a web server indicating whether or not the plant ordered is in stock or needs to be back ordered. We will accomplish this by making changes to the PatsUserInterface interface, the TestPat class, and the Order class.
-- Add the abstract method “void backorder(Order o);” to PatsUserInterface.
-- Write the “public void backorder(Order o)” method in the TestPat class. It should print a message indicating that the plant is backordered and print the name of the plant.
-- Change the Order class as follows:
- Create a URL object using the string http://komar.cs.stthomas.edu/servlet/PlantInStock?plant= concatenated with the name of the plant. Use that URL object to get an input stream and use it to call the readLine() method.
- You will get back a string that says either “Okay” or “Out” indicating whether that product is in stock (Okay) or out of stock (Out). If out of stock, add two days to the delivery time and call the backorder method of the user interface.
- Once you’ve determined the total time to sleep, continue with the regular sleeping and waking done above.
- Note: make sure you put all this new code in a try…catch structure.
III. Additional user interface functionality. Add the following methods to the TestPat class:
-- addCustomer() – code needed to prompt for customer data and add a new customer object to the customers collection.
-- addVendor() – code needed to prompt for vendor data and add a new vendor to the vendors collection.
-- addPlant() – code needed to prompt for plant data and add a new plant to the inventory.
-- Each method should check the data entered to make sure there is not already an object with that data – e.g., not a plant with the same name as the one to add.
-- In the constructor of the TestPat class, display a menu of choices for the user, including a choice to quit the program. The menu should include all the user methods in the class.