Arrays of objects will demonstrated in this lab by developing a Java application to create and maintain a store's catalog of offerings. You may use either an Array or an ArrayList. Your classes should be complete with toString and equals methods and must ensure data integrity and encapsulation.
Service Classes
The CatalogItem class defines a single item in the store’s catalog. Each item has a integer itemID, which uniquely identifies the item, a description, and a cost value which must be greater than 0. All fields should be private, with accessor and mutator methods defined. Provide a default constructor which sets the fields to their default values and an overloaded constructor which accepts values for all three fields. A toString method should be defined to return the itemID, description, and cost, formatted in currency, as a single descriptive string. An equals method should be included. Two CatalogItems are considered equal when their three field values are the same. Your class should be documented using Javadocs. See class diagram below.
The Catalog class will maintain a list of CatalogItem objects. You may implement the Catalog list using either an array or an Arraylist. The Catalog class should be capable of storing up to 100 CatalogItem objects in its list. However, at any given time, there is likely less than 100 CatalogItem objects. The list and all of its object elements should be maintained privately and not exposed to the client except through the methods provided.
The class's default constructor should instantiate an empty list of the maximum number of elements. The Catalog class should implement methods to return list content as String data acceptable for display, add a CatalogItem to the list, remove a CatalogItem from the list, locate items in the list, change the cost of a single CatalogItem in the list, increase the cost of all CatalogItem objects in the list by a percentage amount. Method descriptions are below:
•The add method should ensure that only unique CatalogItem objects are added to the list. In other words, the method must ensure that the given itemID is not in use. There should be two versions of the add method: one should accept a CatalogItem object to add to the list, while the second should accept an itemId, description, and cost for a CatalogItem which will be created and then added to the list.
•The remove method should delete a single CatalogItem from the list based upon a given itemID.
•The find method should accept a String keyword phrase and return a single String of all CatalogItem objects where the keyword phrase was found within the description. For easy display, include the newline ('\n') character in the String between the CatalogItems when more than 1 item is found.
•The changeCost method should accept a single itemID and new cost and change the cost of the matching CatalogItem object.
•The increaseCost method should accept a percentage amount and increase the cost of all CatalogItem objects on the list.
•The toString method should return the entire list as a String. For easy display, include the newline ('\n') character in the String between the CatalogItems.
•An equals method is required. Two Catalogs are considered equal when their list contains the same data in the same order.
Ensure that encapsulation is maintained in your class. In the case where an add, change, or remove is unsuccessful due to a duplicate or non-existent itemId, the Catalog class should report the error to the err class via the print method (System.err.print()).
Your class should be documented using Javadocs. See class diagram below. Note: you may add private fields and methods to benefit required methods. Constructors are not listed.
Client application
Create a client application to test the Catalog class. The driver should perform the following functions:
Create a new instance of a Catalog
Provide a menu driven (text-based) user interface to
Display the entire Catalog
Display catalog items based upon a keyword supplied by the user
Add a new item to the Catalog
Remove a Catalog item
Change the cost of a Catalog item
Increase the cost of all items
End the application
Display the user interface as a list of choices, allowing the user to indicate their desired option. Loop on the menu until the user instructs the application to end.
Your application will begin with an empty list.
Evaluation:
Classes must compile without syntax errors or will not be evaluated. This lab is worth 30 points. Points will be distributed as follows:
•CatalogItem class (6 points)
◦Definition of constructors, accessors, and mutators to support class fields
◦Validation of class fields as needed
◦toString and equals methods
◦Methods produce correct results
◦Methods contain no end-user I/O
◦Code aheres to the style guide
•Catalog Class (18 points)
◦Supports and array or ArrayList of CatalogItem objects
◦Definition of constructors, accessors, and mutators to support class fields
◦Validation of class fields as needed
◦Methods supporting maintaince of array/ArrayList as specified
◦Methods produce correct results and ensures encapsulation of class data
◦Methods contain no end-user I/O
◦Code aheres to the style guide
•Client class (6 points)
◦Supports communication with the end-user
◦Main method utilizes the Catalog service class to meet the objectives of the application
◦Code aheres to the style guide
•On time (late penalty of 7 points assessed for projects submitted late)
6 answers
You'll probably get more useful help if you break it down into tasks - starting with the writing of the CatalogItem class, I suspect - and then ask for any help you need with specific parts that are giving you problems.
For a programming project like this one, you have correctly done the first step, namely to provide all pertinent information related to the project.
However, to make sure you get your help in an efficient manner, we will need more input from you, for example:
1. context
It is clear that this is not your first course in Java. Not only are you capable of looking up information from the API, you are able to design and create your own classes, you are supposed to understand data integrity, encapsulation, overriding methods, constructors, overloading, and so on. You could tell us which aspects of the project requirements pose potential problems to you.
2. Preparatory work.
You could describe what you have done for the design of the project, for example the data structure, for which you were given a choice of arrays or the ArrayList class. Have you evaluated the merits of each choice in consideration of the project requirements? Have you decided to use one or the other, and why?
You should have started designing or even coding. If you encounter difficulties, tell us where you could use help. Hope to hear from you soon.
1. The specifications do not require sorting the list.
2. There will be adding and deletion of members. With an ArrayList, it will not be necessary to "compact" the list after a deletion.
3. The specification give a maximum of 100 items. ArrayList will automatically increase when necessary.
The catalog class could be done like:
class Catalog
{
ArrayList<CatalogItem> list;
Catalog() // constructor
{
list=new public ArrayList<CatalogItem>(100);
}
// for 100 items to start with
// add other methods to insert items into the list
public void addItem(CatalogItem item)
{
list.add(item); // look up API for other options
}
public CatalogItem getItem()...
...
...
}
If you need more details, post again.
list=new public ArrayList<CatalogItem>(100);
produces a few errors, I already renamed the variables to what was needed for it to work properly, but im getting a bunch of small errors