JAVA language This programming assignment will expand on our usage of arrays, wh
ID: 3769404 • Letter: J
Question
JAVA language
This programming assignment will expand on our usage of arrays, when reading and writing to files. The purpose of this assignment is to learn how to interact with a binary file to store information.
The programmer will create an application called “Inventory”. This application will read the contents of a binary inventory file (inventory.bin) and store the contents into an array of class type InventoryItems. The variables contained in this class include the Item Name, the amount of items on hand, and the current price.
Your application will contain a few user options (sample below):
INVENTORY File System
A. Inventory File Name []
B. Display Inventory [0]
C. Add/Modify Inventory Item
D. Delete Inventory Item
E. Save Updates
Q. Quit
User Choice (A-E,Q):
The application will also use a local text configuration file (config.txt), which stores the location of the inventory file and the number of items in the inventory list. This information can be stored in any manner as you wish. When initiating the application, it will read the configuration file to find the location of the inventory file. If the inventory file exists, the inventory items will automatically be read.
The application will create an ItemNotFoundException, which will be used when searching the database for an existing item. The application will contain a method for searching the database for a file, this method will return a ItemNotFoundException if the item is not in the inventory list.
The application will prompt the user for an item. After the item has been entered, the application will search the existing database to determine if the item already exists. If the item exists, the application will prompt the user for the new price and number of items on hand. If the item does not exist, the application will prompt to enter the original price and the number of items on hand.
If the user selects to delete an item, the application will search the database for the item. If the item is contained in the inventory, the item will be deleted. If the item is not in the database, the user will receive an “Item Not Found” error.
Updates to the inventory file will only be made if the user selects to “Save Updates”
The assignment will be graded based upon all tasks being performed and handed in with all required documentation.
Description Points
Proper implementation and use of config.txt configuration file 10 points
Proper implementation and use of inventory.bin binary file 10 points
Proper implementation and use of ItemNotFoundException 10 points
Add / Modify Inventory Item 5 points
Displaying the Inventory Items 5 points
Delete Inventory Item 5 points
Proper updating of configuration and inventory files 5 points
***
Sorting the array of inventory items by name is a plus if you can. The sorting can be done in one of two different ways:
When the user enters a new inventory item, the item is sorted and stored in the array
When the user displays the inventory list, the items are sorted when the items are displayed
Explanation / Answer
Binary Inventory Application:
An inventory control system is an integrated package of software and hardware used in warehouse operations, and elsewhere, to monitor the quantity, location and status of inventory as well as the related shipping, receiving, picking and putaway processes In common usage, the term may also refer to just the software components.
extends atg.repository.dp.DerivationMethodImpl
This derivation method is used to obtain inventory information for a specified catalogRefId. The catalogRefId that is used to query the atg.commerce.inventory.InventoryManagerInventoryManager is obtained from a value in the expression list. Because the property is dervied via logic (querying an inventory manager), it is impossible to query based upon this property. This property can only be accessed for read-only information.
An example of how this method property might be used is as follows: <property name="inventoryLevel"> <derivation method="InventoryLevel"> <expression>catalogRefId</expression> </derivation> </property>
This configuration assumes that the repository item on which this property is configured has a property named catalogRefId . That String value of the catalogRefId property is obtained and is used to query the inventory system. This information can then be used in a variety of ways:
Method Summaryprotected QuerycreateQuery(int pQueryType, boolean pDerivedPropertyOnLeft, boolean pCountDerivedProperty, QueryExpression pOther, int pOperator, boolean pIgnoreCase,QueryExpression pMinScore, QueryExpression pSearchStringFormat, Query pItemQuery, QueryBuilder pBuilder, atg.repository.query.PropertyQueryExpression pParentProperty, java.util.List pChildPropertyList)
Do the real work of creating a query. java.lang.ObjectderivePropertyValue(java.lang.Object pBean)
This method is not supported. java.lang.ObjectderivePropertyValue(RepositoryItemImpl pItem)
This method will return the inventory level associated with the passed in catalogRefId.protected java.lang.StringgetCatalogRefId(java.util.List pList, RepositoryItemImpl pItem)
Given a list of PropertyExpressionPropertyExpression objects, return the catalogRefId. InventoryManagergetInventoryManager()
Return the inventoryManager property. atg.repository.dp.ExpressiongetPropertyOrigin(RepositoryItemImpl pItem)
Determine from where the specified property value is derived, if applicable. booleanisQueryable()
Because this property derives its value from a InventoryManager service, it is impossible to query on it. booleanisThrowExceptionOnInventoryException()
Return the throwExceptionOnInventoryException property. voidsetThrowExceptionOnInventoryException(boolean pThrowExceptionOnInventoryException)
Set the throwExceptionOnInventoryException property. java.util.Listvalidate()
Validate the derivation.
// Import statements go here
You either have to have an array of Product as a member of the InventoryPart2 class OR passed into the sortProductArray method. You'll have to change that method to return a reference to the sorted array if you choose the latter.
Your Product array is in the static main method and not part of the object, so you've got a problem. I'd recommend that you do something like this:
Object oriented programming is about encapsulation and information hiding. Write the class in such a way that clients don't have to know or care whether you're using an array or something else to hold onto Products. You're abstracting the idea of Inventory here.
I removed those comments you add everywhere. They're just clutter; I'd recommend that you not do that anymore. Better to make your code more readable and self-documenting by using better variable and method names.
This still isn't the way I'd recommend that you write it, but it works. You're more likely to see why this works if I don't alter it too much.
Just in case you're interested, here's how I might write it:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.