Starting from:

$30

CST8130-Assignment 1 Inventory System Solved

In this assignment, you will write efficient Java code to create a basic inventory system using a dynamically allocated data structure to hold the inventory and another dynamically allocated array to hold a record of transactions.  Your code must  handle every single possible condition.   The inventory system will contain two types of items – items that are purchased from a supplier; and items that our company manufactures which contains items purchased.  Our program will run with a basic menu that allows the user to add an item to inventory, display to the screen the inventory, buy an item (ie add to the quantity of that item) and sell an item (ie subtract from the quantity of that item).  You are allowed to buy and sell any item (purchased or manufactured) in the inventory.

 

Note – You are welcome to add to the assignment, but I am trying to bound the scope of the assignment so that you do not have too much work.   Assume that all string field input does not contain spaces which will make the input easier.

 

Hint:  This assignment needs to be tackled in a     structured fashion in order for it to be finished quickly.   Do not write more than 20-30 lines of code at a time without running your program.   I will be discussing structured strategies  in class.   Enjoy!!

 

 

 The following is a suggestion of how to structure the code (you may make changes, but they must follow Object-Oriented Principles as discussed in class)

 

Item class:

·        Has (private) data members: 

o   itemCode (int)

o   itemName (String)

o   itemQuantityInStock (int)

o   itemPrice (float)

·        Has methods:

o   Constructors

o    boolean addItem (Scanner) –reads from the Scanner object passed in  and fills the data member fields with valid data; method  returns true if successfully reads in all fields else returns false

o   String toString()

o   boolean updateItem (int amount) – updates the quantity field by amount  (note amount could be positive or negative) – returns true if successful else false  Note- quantityInStock field can never be less than 0.

o   boolean isEqual (Item)  returns true if the itemCode of the object being acted on and the item object parameter are the same value

o   boolean inputCode(Scanner) – reads a valid itemCode from the Scanner object and returns true/false if successful

NOTE:   because the data members are all private in the Item class, only this class can access them.  So If you need to do something to any of these data members, you must write a method to do it (for example – methods  isEqual,   inputCode)

 

 

PurchasedItem class – extended from Item class

·        has (private) data members:

o   supplierName (String)

·        has methods:

o   constructor

o   boolean addItem (Scanner) – per Item class

o   String toString()

 

 

ManufacturedItem class – extended from Item class

·        has (private) data members:

o   itemsUsed – array of 10 ints (to contain the itemCodes)

o   numItemsUsed (int)

·        has methods:

o   constructor

o   boolean addItem (Scanner) – per Item class

o   String toString()

 

 

 

 

Inventory class

·        Has (private) data members:

o   inventory (dynamically allocated array of Item objects)

o   numItems (int)

·        Has methods:

o   Constructors

o   boolean addItem (Scanner) – adds an item to the inventory array – (uses polymorphism to  call addItem method  in the correct derived Item class for input of the fields of the Item)

o   String toString()

o   int alreadyExists (Item) – returns the index of an Item in the inventory array with the same itemCode as the Item object in the parameter list, else returns -1

o   boolean updateQuantity (Scanner, boolean) – reads in an itemCode to update and quantity to update by and updates that item by the input quantity in the inventory array.  The boolean parameter is used to denote whether buying operation or selling operation is occurring.  Method returns true/false on whether update was successful or not

 

Assign1Main class

·        Has methods:  

o   main  - menu processing

 

Sample Output: green is user input

Enter 1 to add an item to inventory

2 to display current inventory

3 buy some of an item

4 sell some of an item 

5 to quit

1

Do you wish to add a purchased item (enter P/p) or manufactured (enter anything else)? p

Enter the code for the item: 123

Enter the name for the item: paper

Enter the quantity for the item: 100

Enter the price of the item: 0.50

Enter the name of the supplier:

Staples

 

Enter 1 to add an item to inventory

2 to display current inventory

3 buy some of an item

4 sell some of an item 

5 to quit

1

Do you wish to add a purchased item (enter P/p) or manufactured (enter anything else)? P

Enter the code for the item: ab

Invalid code...please enter integer greater than 0

Enter the code for the item: 234

Enter the name for the item: nails

Enter the quantity for the item: a

Invalid quantity...please enter integer greater than 0

Enter the quantity for the item: -5

Invalid quantity...please enter integer greater than 0

Enter the quantity for the item: 5000

Enter the price of the item: a

Invalid price...please enter float greater than 0

Enter the price of the item: -2

Invalid price...please enter float greater than 0

Enter the price of the item: 2.00

Enter the name of the supplier:

ABConstruction

 

Enter 1 to add an item to inventory

2 to display current inventory

3 buy some of an item

4 sell some of an item 

5 to quit

1

Do you wish to add a purchased item (enter P/p) or manufactured (enter anything else)? m

Enter the code for the item: 444

Enter the name for the item: Instructions

Enter the quantity for the item: 25

Enter the price of the item: 1.00

Enter up to 10 codes used in this item (-1 to quit):

123

-1

 

Enter 1 to add an item to inventory

2 to display current inventory

3 buy some of an item

4 sell some of an item 

5 to quit

2

Inventory:

Item: 123 paper 100 price: $0.5 Supplier: Staples

Item: 234 nails 5000 price: $2.0 Supplier: ABConstruction

Item: 444 Instructions 25 price: $1.0 Codes used: 123,

 

 

Enter 1 to add an item to inventory

2 to display current inventory

3 buy some of an item

4 sell some of an item 

5 to quit

3

Enter valid item code: 456

Code not found in inventory...

Error...could not buy item

 

Enter 1 to add an item to inventory

2 to display current inventory

3 buy some of an item

4 sell some of an item 

5 to quit

3

Enter valid item code: 444

Enter valid quantity : 5

 

Enter 1 to add an item to inventory

2 to display current inventory

3 buy some of an item

4 sell some of an item 

5 to quit

4

Enter valid item code: 123

Enter valid quantity : 50000

Error... could not sell item

 

Enter 1 to add an item to inventory

2 to display current inventory

3 buy some of an item

4 sell some of an item 

5 to quit

2

Inventory:

Item: 123 paper 100 price: $0.5 Supplier: Staples

Item: 234 nails 5000 price: $2.0 Supplier: ABConstruction

Item: 444 Instructions 30 price: $1.0 Codes used: 123,

 

 

Enter 1 to add an item to inventory

2 to display current inventory

3 buy some of an item

4 sell some of an item 

5 to quit

4

Enter valid item code: 123

Enter valid quantity : 9

 

Enter 1 to add an item to inventory

2 to display current inventory

3 buy some of an item

4 sell some of an item 

5 to quit

2

Inventory:

Item: 123 paper 91 price: $0.5 Supplier: Staples

Item: 234 nails 5000 price: $2.0 Supplier: ABConstruction

More products