Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE DO NOT COPY PASTE FROM CHEGG/OTHERWISE I'LL REPORT YOU QUESTION:6 Assignment Create a console application for handling inventory data that uses two classes from
PLEASE DO NOT COPY PASTE FROM CHEGG/OTHERWISE I'LL REPORT YOU
QUESTION:6 Assignment Create a console application for handling inventory data that uses two classes from the InvTracker.java file: InvTracker and Invitem. The user interface, InvTracker, controls an array of Invitem objects. Please submit the InvTracker.java file as your source code. The following are the design requirements: 1) Data from InvTracker: a) an array of type invitem items named items (without an initial assigned size) b) a Scanner scanner (import the java.util.Scanner file) c) a StringTokenizerst scanner (import the file java.util.StringTokenizer) 2) Methods of the InvTracker (all return void) a) name: accepts two parameters: a long and a String. For every element in items with an id equal to the parameter long, the String is assigned as the name field. b) add: takes two parameters: a long and an int. If the id of an element in items matches the parameter long, the parameter int will be added to the amount attribute of that element-use Invitem.add()in Sc. Otherwise, a new Invitem with the parameter long as its id and the parameter int as its quantity will be created, and the items will be expanded to incorporate the new element. c) remove: takes two parameters: a long and an int. If an element in items has an id that matches the parameter long and a quantity that equals or exceeds the parameter int, the parameter int will be deducted from its quantity attribute - use Invitem.drop() in 5c. Otherwise, the message "no matching record found" will be printed. d) display the Invltem's id, name, and quantity, one line per invitem, in a list for each element in items. If items.length == 0, the message "no item records to display" will be printed. e) a function Object() { [native code] }method that accepts no arguments, generates items as an array of size 0, and creates scanner as a new Scanner using the System.in input stream.f) a main method for constructing an invTracker object. After that, an infinite while loop is started to collect user input from the console and process it using the StringTokenizer function. Use the format "method [value 1] [value 2)" in your command. Valuel and value will be used in methods 2a, 2b, and 2c, respectively, but method 2d will not utilise any values. 3) The Invitem class should be defined after the InvTracker class and outside of it, as follows: public class InvTracker / code goes here class Invitem/more code goes here) Only the InvTracker class can be made public. 4) Members of the Invitem data set: a) a unique long identifier; b) a unique String name c) a private integer value 5) Invitem methods: a) public name get and set methods (respectively return or accept a String). The set function takes a String and assigns it to the name attribute of the Invitem object. The get method will retrieve the name attribute's current value. b) public get and set methods for id and quantity that return the Invitem object's id and quantity, respectively. c) public quantity add and drop methods. The add method adds a parameter int to the quantity value of the Invitem; the drop method subtracts the parameter int from the quantity value of the Invitem. d) a function Object(){ [native code] } method that accepts a long as a parameter and returns an Invitem with an id equal to the parameter long, a name equal to an empty String, and a quantity of O. Checking for Errors Any input command that cannot be appropriately interpreted should throw an Exception with the message "invalid command" within the main method's loop. The application should look for the following things: Commands that begin with a nonsensical word Any amount of values after the initial command word that is erroneous (e.g., list 123 or delete 456) Any integer values that aren't positive Furthermore, any modifications to the Invitem quantity that are invalid should result in an Exception (handled within the add or drop method). Check that the parameter is between one and one hundred and that the final quantity is between zero and 9999. Any invalid attempts should display the message "invalid quantity change" rather than changing the quantity. Sequence of Coding To avoid IDE problems (from accessing unwritten data and methods in Invitem), create both class shells in the InvTracker.java file first, then the data and methods in Invitem, and last the code for the data and methods in Inv TrackerStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started