Java Programming



COP 2253 Java Programming

Programming Project #7

Due: Wednesday, May 1, at 11:00 PM

Project Outcomes:

1. Use the Java selection constructs (if, and if else).

2. Use the Java iteration constructs (while, do, for).

3. Use Boolean variables and expressions to control iterations.

4. Use class ArrayLists for storing objects.

5. Proper design techniques.

Prepatory Readings:

Big Java textbook, chapter 1 - 8.

Background Information:

The Unified Modeling Language (UML) provides a useful notation for designing and developing object-oriented software systems. One of the basic components of the UML is a class diagram, which are used to depict the attributes and behaviors of a class. A basic class diagram (as shown in the figure below) has three components. The first is the class name. The second component includes the class's attributes or fields. Each attribute is followed by a colon (:) and its data type. The third component includes the class's behaviors or methods. If the method takes parameters, their types are included in parentheses. Each behavior is also followed by a colon (:) and its return type. If the return value of a method is void, the return type can be omitted. For more information on the UML, refer to .

Project Requirements:

Your job is to implement a simple bookstore information system that keeps track of textbooks and apparels in a bookstore. The information system consists of three classes including a class to model textbooks, a class to model apparel items, the bookstore, and the bookstore tester. The bookstore supports access to specific items in the bookstore and to purchase these items or to order new items for the bookstore. The UML diagram for each class (except the tester class) is given below.

1) Develop a simple class that models textbooks. Each textbook is described by several instance fields:

a. an ID as a String to identify the textbook,

b. a title represented as a String to store the title of the textbook,

c. a list of authors represented as an array of Strings to store author information,

d. a publisher represented as a String to store the publisher information,

e. a price represented as a double to store the price of a book,

f. a status represented as an integer to store if the book is in INSTOCK or ORDERED.

In addition to these fields, the class has the following constructors and methods:

a. A parameterized constructor that initializes the attributes of a textbook.

b. setPrice(double price) to change the price of a textbook.

c. changeStatus(int newStatus) to change the status of a textbook to either INSTOCK or ORDERED. If an invalid status is passed as a parameter, the method prints an error message to the screen and sets the status to UNKNOWN.

d. Accessor methods for all instance fields.

e. toString() to return a neatly formatted string that contains all the information stored in the instance fields.

For getAuthors(), the method returns a string of comma-separated author names.

The class also includes three constants to set status values:

a. INSTOCK has value 1 and indicates that the book is in stock.

b. ORDERED has value 2 and indicates that the book has been ordered.

c. UNKNOWN has value 0 and indicates that the book may be ordered or in stock.

|Textbook |

|-id : String |

|-title : String |

|-authors : String[] |

|-publisher : String |

|-price : double |

|-status : int |

|+INSTOCK : int |

|+ORDERED : int |

|+UNKNOWN : int |

|+TextBook (String, String, String[], String, double, int) |

|+setPrice(double) |

|+changeStatus(int) |

|+getId() : String |

|+getTitle() : String |

|+getAuthors() : String |

|+getPublisher() : String |

|+getPrice() : dobule |

|+getStatus() : int |

|+toString() : String |

2) Develop a simple class that models apparels including t-shirts, sweatshirts, and hats. The class has several instance fields:

a. an ID as a String to identify the specific item,

b. a category as a String to store the specific type of apparel,

c. a name as a String to store the name of the apparel item,

d. a size as a String to store the size of the apparel,

e. a price represented as a double to store the price of the apparel item,

f. a status represented as an integer to store if the item is in INSTOCK or ORDERED.

Valid values for the size include "S", "M", "L", "XL", and "XXL" for shirts. Hats come in "S" and "M". Valid values for category is "T-Shirt", "Sweatshirt", and "Hat". If invalid values are entered, an error message must be printed and the size instance field must be set to "UNKNOWN". The same accounts for category information.

In addition to these attributes, the class has the following constructors and methods:

f. A parameterized constructor that initializes the attributes of an apparel item.

g. setPrice(double price) to change the price of the apparel.

h. changeStatus(int newStatus) to change the status of an apparel item to either INSTOCK or ORDERED. If an invalid status is passed as a parameter, the method prints an error message to the screen and sets the status to UNKNOWN.

i. Accessor methods for all instance fields.

j. toString() to return a neatly formatted string that contains all the information stored in the instance fields.

The class also maintains three constants to change status values:

d. INSTOCK has value 1 and indicates that the book is in stock.

e. ORDERED has value 2 and indicates that the book has been ordered.

f. UNKNOWN has value 0 and indicates that the book may be ordered or in stock.

|Apparel |

|-id : String |

|-category : String |

|-name : String |

|-size : String |

|-price : double |

|-status : int |

|+STOCK : int |

|+ORDERED : int |

|+UNKNOWN : int |

|+Apparel (String, String, String, String, double, int) |

|+setPrice(double) |

|+changeStatus(int) |

|+getId() : String |

|+getCategory() : String |

|+getName() : String |

|+getSize() : String |

|+getPrice() : double |

|+getStatus() : int |

|+toString() : String |

3) Develop class Bookstore that keeps track of textbooks and apparel inventory. The Bookstore uses two ArrayLists to store Textbook and Apparel objects. The Bookstore provides several methods to add items to the store and to access items. The following UML diagram describes the class, the constructor, and the methods:

|Bookstore |

|-textbooks : ArrayList |

|-apparel : ArrayList |

|-name : String |

|+Bookstore (String) |

|+getName() : String |

|+getTextbooks() : ArrayList |

|+getTextbooks (String name) : ArrayList |

|+getTextbook (String id) : Textbook |

|+getApparel() : ArrayList |

|+getApparel (String name) : ArrayList |

|+getApparelByCategory (String name) : Arraylist |

|+getApparel (String id) : Apparel |

|+addTextbook (Textbook) |

|+addApparel (Apparel) |

|+buyTextbook (String id) |

|+buyApparel (String id) |

a. The class has three instance fields:

a. name, the name of the bookstore

b. textbooks, an ArrayList storing Textbook objects

c. apparel, an ArrayList storing Apparel objects

b. getName() returns the name of the bookstore.

c. getTextbooks() returns an ArrayList of all the textbook inventory (in-stock and ordered). This method must create a separate copy of the ArrayList before it returns the list. If there are no textbooks in the Bookstore, an empty list is returned.

d. getTextbooks (String name) returns a list of Textbook objects whose title matches the specified name. For example, if called with "Java Programming" the method returns all textbooks with the title "Java Programming" as a new list. This method must create a new copy of an ArrayList that stores all the matched Textbook objects. If no books in the bookstore match the given name, an empty list is returned.

e. getTextbook(String id) returns the Textbook that matches the specified id. If there is no Textbook matching the given id, null is returned.

f. getApparel()returns an ArrayList of all the apparel inventory (in-stock and ordered). This method must create a separate copy of the ArrayList before it returns the list. If there are no apparel items in the Bookstore, an empty list is returned.

g. getApparel (String name) returns a list of Apparel objects whose title matches the specified name. For example, if called with "Argo T-shirt" the method returns all Apparel objects with the name "Argo T-shirt" as a new list. This method must create a new copy of an ArrayList that stores all the matched Apparel objects. If no apparel items in the bookstore match the given name, an empty list is returned.

h. getApparelByCategory(String name)returns a list of Apparel objects of a particular category. For example, if called with " Sweatshirt " the method returns all Apparel objects that are Sweatshirt by category in a new list. This method must create a new copy of an ArrayList that stores all the matched Apparel objects. If no apparel items in the Bookstore match the given category name, an empty list is returned.

i. getApparel (String id) returns the apparel item that matches the specified id. If there is no item matching the given id, null is returned.

j. addTextbook(Textbook) adds a new Textbook to the inventory of the bookstore.

k. addApparel(Apparel) adds a new Apparel to the inventory of the bookstore.

l. buyTextbook(String id) removes a Textbook object from the list of textbooks of the Bookstore. If the id does not match any Textbook object in the list, an error message is printed to the screen.

m. buyApparel(String id) removes an Apparel object from the list of apparel items of the Bookstore. If the id does not match any Apparel object in the list, an error message is printed to the screen.

4) Design a tester class called BookstoreTester. The tester class has a main() method and tests the functionality of the class Bookstore as follows:

a. Create Bookstore and name it "UWF Bookstore".

b. Create a minimum of three Textbook objects and add them to the bookstore.

c. Create 6 Apparel objects, two of each category, and add them to the bookstore.

d. Setup a loop to:

i. Display a short menu that allows a user to perform different actions in the bookstore such as looking up textbooks, or apparel items, or purchasing items. Use all of the accessor methods in the Bookstore to access specific items. Use the given methods to make purchases.

ii. Prompt the user for a specific action.

iii. Depending on the specific action prompt the user for additional input such as the id of a textbook or apparel category, etc. You might want to use static methods in main() to handle each menu item separately.

iv. Perform the action and display results such as the list of textbooks that the user has requested. Use the toString() method to display bookstore items on the screen.

v. Prompt the user for continued access to the bookstore or termination.

Your program should handle input error gracefully. For example, if a particular textbook is searched and not found, the program should display a message such as "Selected textbook not found." Feel free to experiment with the tester program to develop a useful program.

Implementation Notes:

1) All accessor methods in Bookstore must create a new ArrayList to copy objects into the new list. This requires loops to access objects from the corresponding instance fields and adding them to the new ArrayList.

2) Proper error handling is essential for this project.

3) Javadoc must be used to document Bookstore, Textbook, and Apparel.

 

Submission Requirements:

Your project submission should follow the instructions below. Any submissions that do not follow the stated requirements will not be graded.

1. Follow the submission requirements of your instructor.

2. You should have files for this assignment:

a. Textbook.java - The Textbook class,

b. Textbook.html - The documentation file generated from your class (you do not have to turn this file in),

c. Apparel.java - The Apparel class,

d. Apparel.html - The documentation file generated from your class (you do not have to turn this file in),

e. Bookstore.java - The Bookstore class,

f. Bookstore.html - The documentation file generated from your class (you do not have to turn this file in),

g. Bookstore Tester.java - A driver program for your Bookstore class.

3. Remember to compile and run your program one last time before you submit it. If your program will not compile, the graders will not be responsible for trying to test it.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download