QMCS 281

Pat’s Potted Plants

First Assignment

 

We will start with creating a number of classes that will eventually be part of a fully functioning ordering system for Pat’s Potted Plants business. You should create the following classes in the order specified and frequently compile your code as you go along. Please, please don’t try to write all the code for all the classes without frequent compiles. In addition, you should have a class with a main method that tests out each class and sets of classes as you go along.

 

Here are the classes:

 

Customer.java – this class is the parent class for all of Pat’s customers. It will hold a name, an id and a location for each customer on campus. All the variables are Strings. It should have setters and getters for each variable. Finally, you need to override the toString method (public String toString()) from the Object class. The toString method should format a string the way you want the data to print and return that string. (Don’t forget a constructor.)

 

Student.java – this class is a child of the Customer class. It will add a variable for student major and have appropriate setters and getters for that string value. It should override the toString method of the parent class. (Don’t forget a constructor.)

 

Staff.java – this class is a child of the Customer class. It will add a variable for staff member department and have appropriate setters and getters for that string value. It should override the toString method of the parent class. (Don’t forget a constructor.)

 

(At this point would be a good time to test out the code written in the above three classes.)

 

Customers.java – this class is a “collection class” for the Customer objects. It will have an array of Customer objects as its only variable. The constructor will declare the array size (make it 3 for now) and instantiate three Customer objects (at least one Student and one Staff) in the three array positions. It will need a getCustomer method that accepts a customer ID and returns the Customer object with that ID or null if there is no customer with that ID. Finally, there should be a toString method to produce a string containing all the customer objects.

 

(This would also be an ideal time to check out the code for all four classes above.)

 

Vendor.java – this class will be for vendor objects. Each vendor has a name, an address and the average number of days it takes them to deliver an order. The constructor should accept these values for the object. Again, appropriate setters and getters are needed. Finally, it needs a toString method.

 

Vendors.java – this is the collection class for vendor objects. It will have an array of Vendor objects as its only data item. Its constructor will declare the array size of three, and instantiate each array location with a Vendor object. Write a getVendor method to return a vendor whose name matches the parameter passes. Finally, there needs to be a toString method to display all of the Vendors in the array.

 

(Make sure you test out these last two classes at this point.)

 

Plant.java – this is the class for individual plants. Each plant has a name, price, number on hand, and a vendor object. The constructor will accept all these values including a Vendor object passed to it. It needs appropriate setters and getters as well as a toString method.

 

Inventory.java – this is the collection class for plants. It will have an array of Plant objects as its only data item. The constructor will declare the array size of three and instantiate each of the three Plant items in the array. The constructor needs to accept a Vendors object so it can use the getVendor method to get vendor objects when instantiating the plant objects. Like the other collection classes there needs to be a getPlant method and a toString method.

 

(Make sure you test out the code here also.)

 

PatsPottedPlants.java – this class represents Pat’s business. Its variables include a Customers object, an Inventory object, and a Vendors object. The constructor instantiates new objects of each type. It does not need setters, but should have getters for the three data items. There should also be three methods to print out the collections – printCustomers, printInventory, and printVendors.

 

TestPat.java – this class has the main method. You should use this along the way to test out the classes as you create them. It should end up testing PatsPottedPlants using code like the following:

 

                        PatsPottedPlants pats = new PatsPottedPlants();

                        pats.printVendors();

                        pats.printInventory();

                        pats.printCustomers();