Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lets assume that you are running a small store and would like to keep an inventory of items in your store. Each different item could

Lets assume that you are running a small store and would like to keep an inventory of items in your store. Each different item could be placed into your program as an individual object. For this lab I would like you to create a class called Item that contains the following: instance variables (make these private): description (a String) quantity (a integer) price (a double) Constructors (2): One that sets all three items based on values sent in, and one that sets description and price only, putting quantity to 0 Accessors and Modifiers (6 total): Make all three for each Once the class is created make a program in another file that creates a five element array of Item objects. Fill the array up with the following: three Item objects using the first constructor: (You can do these one line at a time, loop is not required) Spoon Fork Knife qty 14 qty 18 qty 12 $1.25 $1.50 $2.35 Two more objects using the second constructor: Dish Bowl $5.95 $4.99 Using the Modifier methods change the price of a Fork to $1.75, and make the quantity of Dishes to be 5 and Bowls to be 8. Change the name of Knife to be Butter Knife. Remember that each element in the array is an Item object, so to reference an Item object in the array we can do this: Array_name[1].setPrice(1.75). Using a loop and an output message, for every Item object output to the screen (in one line) all the values stored for that object (using Accessor methods). For example: We have 14 Spoon (s) at a price of $1.25 each Add a class constant which is an integer and represents the minimum quantity all items should have in stock( Use the value 12). Add a Boolean method called needToOrder( ) which returns true if quantity of item is less than this minimum value. Add toString( ) which will output this way: Item: Fork Qty: 12 Cost: $1.75 Add method called itemWorth( ) which returns current total price of the object (single object) based on the quantity on hand (qty * price) Add method called sellSome(int) which reduces quantity of the object by the amount inputted. Add an instance method called greaterThan( Item ) which returns a boolean based on whether the itemWorth of the calling object is worth more than the passed in object. Add Javadoc comments to class comments before each method Now write a better driver program to test this class. Create an Array of 10 Items (the Inventory). Do not use a premade class such as ArrayList. We will be adding and removing Items from this Inventory. Start with an empty array. We will assume that there will always be 10 or less. When we have less than 10 we will always use only the beginning of the array, the remaining values will be null. If we delete any items in the middle of the list, you must shift them in a way to keep all the items in the beginning. For the main program you will create a text menu that comes up on the output screen giving the user a bunch of choices. As they pick a choice, that action will be done and then the menu will repeat to the screen again. A switch statement and/or having a link to additional static methods could be useful. Your menu will do the following: 1 list all items -use toString on each filled array location 2 list the items that need to be ordered -process through the array until reach null -call needToOrder on each and show the true results -Report if no items need to be ordered 3 add an item to the inventory -add it at the first null location in the array -ask the user to give the 3 inputs and then use the constructor to create one -Report if there is not room to add another item 4 Report total inventory cost -search through entire array, and sum up the itemWorths -report the total. 5 Report item that is worth the most (Use greaterThan method) 6 Sellsome of an item -Ask user for description, find array element and ask user to say how much is sold and update quantity. -Report if not found should not crash 7 Remove an item from list -Ask user for description, find array element -Report if not found should not crash -set array location to null (make sure to shift array to fix holes) 8 Clear list. set all array locations to null 9 End program Test all of your menu choices, make sure to remove items in the middle of the list and check if the rest of the choices still work. I will test very extensively, so be prepared to do so also. Each of these programs must be done in a separate file. Name the class Item.java, and the driver program Inventory.java. Name the class in each file these names as well. If you do not name these files correctly you will lose points

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions