Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

https://docs.google.com/document/d/16BI-eiN4LBLoJAWD5E6_xaROOwozlVtPjC7vArf6MOk/edit?usp=sharing here is the problem and I have put the editable code on google docs and the attached link to it, so hopefully now it's

image text in transcribed

image text in transcribed

https://docs.google.com/document/d/16BI-eiN4LBLoJAWD5E6_xaROOwozlVtPjC7vArf6MOk/edit?usp=sharing

here is the problem and I have put the editable code on google docs and the attached link to it, so hopefully now it's easy for you all to help me out with it!

Please try to do it ASAP because I've been waiting on this since yesterday!

let me know when it's done by posting a comment please

Thank you

Problem Description You have decided you want to create an Inventory management system, which can keep track of items, their weights, and their prices. Solution Descriptionn We have provided you with the skeletons of three classes: Item, Inventory and Inventory Manager. Your task is to fill them in so that they meet the following requirements: em You will create two instance fields in Item: - A double field named "weight A double field named "price". .In addition, you will fill in the first constructor. Just fill in the TODO lines provided. Inventory You will create an Item[] field in Inventory called contents You will write the merge method. This works as follows: - You are given another inventory. You can access its contents with other.contents You need to first figure out how big the merged array should be. You must add together the lengths of contents and other.contents You need to create a new Item whose size is the sum we computed above. -You need to copy all of contents into that Item created above - You need to copy all of other.contents into that Item created above. You need to write the getItem method. This wor ks as follows: First, check if the given index is valid. (Think about when an array index is valid versus invalid.) If it is invalid, return null Otherwise, if it is valid, return the value in contents at the given index. You need to write the putItem method. This works as follows: First, check if the given index is valid. (Think about when an array index is valid versus invalid.) If it is invalid, return false Otherwise, if it is valid, set the value in contents at the given index to item and return true. .You need to write the getContentsLength method, which just returns the length of contents InventoryManager You will fill in a mergeInventories method, which just takes in two Inventorys and merges them using the met hods you wrote above. You will fill in a addItem method, which just takes in an Inventory to put the item into, an Item, to put in the Inventory, and an index for where in the Inventory to put the Item. If it doesn't work print "Can't add there.". You will fill in a printItem method, which takes in an Item and prints (name, price, weight), where name, price and weight are filled in with the proper values from Item. price and weight should be printed to two decimal points. If the Item is null, print (empty, 0, 0). Do not print a new-line after is You will fill in a showInventory method. If the Inventory is null, or if getContentsLength returns a value less than or equal to zero, just print . Otherwise, print a comma separated list of the Items in the Inventory's contents array. An example is given below: (A, 0.0, 0.0), (B, 1.0, 0.0), (empty, o, o), (empty, 0, 0), Your formatting (spaces, no extra commas, etc.) must match this exactly. Print a new-line after your list or after the "O". Allowed Imports To prevent trivialization of the assignment, you are only allowed to import the following classes: java.util.Scanner java.util.Random If you would like to import anything else, ask on Piazza. Based on what we have seen in the past, we'll go ahead and say you cannot import the following classes: java.util.Arrays java.util.ArrayList Or any List Feature Restrictions There are a few feat ures and methods in Java that overly simplify the concepts we are trying to teach. For that reason, do not use any of the following in your final submission: var (the reserved keyword) System.arraycopy In addition, you may not use System.exit as it will break the autograder

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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