QMCS 281
Pat’s Potted Plants
Again, first the good news! The classes Customer, Plant, Staff, Student, and Vendor will be unchanged.
1. The three collection classes, Customers, Inventory, and Vendors will be changed to read the data in from files rather than create arrays of Strings. Each will need to be changed to do the following:
- import java.io.*;
- The constructor will create an object (either Scanner of BufferedReader) to read a file (customers.dat, inventory.dat, and vendors.dat are provided for this purpose). Each of these files has a comma delimited String with the same data as was used previously. After each record is read in, the String will need to be parsed and the data items used to create the appropriate objects.
- Note that the first field in the customers.dat file is an “S” for a student, or an “E” for an employee (staff).
- Remember to use a try and catch block for this file IO.
- Remove the array of Strings you used for the data input.
- Everything else in the Customers, Inventory, and Vendors classes should remain unchanged.
2. There will be one new file you will need to create:
- PatsUserInterface.java will contain the following code for the interface:
public interface PatsUserInterface
{
void orderDone(Order o);
}
-The TestPat program must now implement PatsUserInterface and have a method called orderDone that accepts an Order object and returns nothing. The method should print a message indicating that an Order has been delivered and the details of the order. We will be using this later when we implement threading in our application.
- In the Order.java class you need to make the following changes:
- Declare another private variable of type PatsUserInterface.
- Add a parameter of type PatsUserInterface to the constructor and store the value passed to the constructor in the variable declared. Again, we will use this later when we use threading.
3. Finally, there will be extensive changes to the TestPat program.
- Write a constructor for the class. This is where the processing will begin.
- The main method should now have nothing in it but the following code:
new TestPat();
- Declare private, class variables for PatsPottedPlants, Customers, Vendors, Inventory, Orders, and a BufferedReader for keyboard input. These variables will be used throughout the class.
- The constructor should instantiate the keyboard input object and PatsPottedPlants object. Use the appropriate get methods to get the collection class objects from PatsPottedPlants.
- The last thing the constructor will do is call the enterOrder method which resides in the TestPat class.
- enterOrder method. This method accepts no parameters and returns nothing. It should prompt for input of a customer number and plant name. It should check to make sure that the customer number is valid and the plant name is valid. If not, it should prompt again for the appropriate item. When valid customer and plant objects are obtained, it can then add a new Order to the Orders collection. Assuming the Orders collection object name is orders, the Customer Id is called cust, and the Plant name is called plant, the following code will accomplish this:
orders.addOrder(cust, plant, this);
Note the use of “this” to pass the current user interface object to the Order object.
- The enterOrder method should allow the user to enter as many orders as they want. When done entering orders, display all the orders.
- Note that you will need to import java.io.* for the keyboard input. You will also need to add the phrase “throws IOException” to the enterOrder, constructor, and main methods of the class.
We will continue to add functionality to the system in future assignments.