Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java plz . . . Create an inventory program that can be used for a range of different products. Topic(s): Modifying programs Creating static methods

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
java plz
. . . Create an inventory program that can be used for a range of different products. Topic(s): Modifying programs Creating static methods Using parameters in a method Return a value from a method Adding methods(behaviors) to an existing class 1. Open the inventory program that was updated in Project 7: Creating an inventory project 2. Create two new methods in the Product class, one that will allow the user to add to the number of units in stock (addtoinventory), and one that will allow the user to deduct from the number of units in stock (deductFromInventory). Both methods should accept a parameter (quantity) that holds the number of items to add/deduct. Place these under your constructors. 3. Modify the ProductTester class so that the user can view the products through a user interface that is based on a menu system. A. Display a menu system that will display options and return the menu choice entered by the user. a) The method should be called getMenuOption, return an integer value, and take a Scanner object as a parameter. Write the code under main. b) The menu should look like the following: 1. View Inventory 2. Add Stock 3. Deduct Stock 4. Discontinue Product 0. Exit Please enter a menu option: c) Only numbers between 0 and 4 should be accepted, any other input should force a re- prompt to the user. When it is time for the user to enter a number, you can assume the user does not type a non-numeric value. You do not have to test for this kind of non- numeric error. B. Create a method that will display the index value of the array and name of each product allowing the user to select the product that they want to update (add/deduct). a) The method should be called getProductNumber, return an integer value and take the products array and a Scanner object as parameters. It should have a single local variable named productChoice of type integer that is initialized to -1. Write the code under main. b) A traditional for loop should be used to display the index value and the product name. Use the length of the array to terminate the loop. The name for each product can be accessed through its appropriate getter method c) The user should only be allowed to enter values between 0 and 1 less than the length of the array. You can assume he does not type some non-numeric value. C. Create a method that will add stock values to each identified product. a) The method should be called addinventory, have no return value and take the products array and a Scanner object as parameters. It should have two local variables named productChoice that does not need to be initialized and another named updateValue that should be initialized to -1. Both local variables should be able to store integer values. Write the code under main. b) Add a method call to the getProduct Number method passing the correct parameters and saving the result in the productChoice variable. c) The user should be prompted with the message "How many products do you want to add?" and only be allowed to enter positive values of 0 and above. All input should have both appropriate error message. d) Once a valid update value has been added then the selected product stock levels should be updated through the addTolnventory method that you created earlier. The productChoice variable is used to identify the index value of the product in the array and the updateValue is the amount of stock to be added. D. Create a method that will deduct stock values to each identified product. a) Follow the same procedure as you did to add stock but name your method deductinventory. The restrictions on his input are that the value must be 0 or greater and cannot be greater than the current quantity of stock for that product. b) Use the deductFromInventory method to make the change to the product object in the array. All input should have both appropriate error messages. E. The final menu option to implement is the ability to mark stock as discontinued. a) The method should be called discontinuelnventory, have no return value and take the products array and a Scanner object as parameters. It should have a single local variable named productChoice that stores an integer value and does not need to be initialized. Write the code under main b) Add a method call to the getProduct Number method passing the correct parameters and saving the result in the productChoice variable. c) Now use the setActive method to set the value of active to false for the chosen product object. F. You now need to create a method that will bring it all together. a) The method should be called executeMenuChoice and have no return value. It should also take the menu choice, products array, and a Scanner object as parameters. It does not require any local variables. Write the code under main. b) Use a switch statement to execute the methods that you have created in this exercise. For each case statement, use an output statement that will display one of the following heading before executing the appropriate method: View Product List Add Stock Deduct Stock Discontinue Stock 7 8- 10 4. The final stage is to update the main method to make use of the new functionality. Update your code so that your main method matches the following code: Product.java ProductTester.java X 6 public class Product Tester { public static void main(String[] args) { //create a Scanner object for keyboard input Scanner in = new Scanner(System.in); int maxSize, menuchoice; 12 13 maxSize - getNumProducts(in); if(maxSize --) { V/Display a no products message if zero is entered System.out.println("No products required!"); Jelse Product() products - new Product[maxSize); 19 addTo Inventory (products, in): do menuchoice - getMenuOption(in); 22 executeMenuChoice (menuChoice, products, in); Jwhile(menuChoice1-e); }//endit }//end method wain 5. Run and test your code 6. Save your project. 14 15 16 17 13 Sample run 1: Enter the number of products you would like to add. Enter 0 (zero) if you do not wish to add products: 3 Please enter the product name: Pencil Please enter the quantity of stock for this product: 25 Please enter the price for this product: 9.99 Please enter the item number: 1 Please enter the product name: Pen Please enter the quantity of stock for this product: 75 Please enter the price for this product: 8.99 Please enter the item number: 2 Please enter the product name: Marker Please enter the quantity of stock for this product: 200 Please enter the price for this product: 7.75 Please enter the item number: 3 1. View Inventory 2. Add Stock 3. Deduct Stock 4. Discontinue Product 0. Exit Please enter a menu option: 1 View Product List Item Number: 1 Name : Pencil Quantity in stock: 25 Price : 9.99 Stock Value : 249.75 Product Status : Active Item Number: 2 Name : Pen Quantity in stock: 75 Price : 8.99

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 3 Lnai 8726

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448440, 978-3662448441

More Books

Students also viewed these Databases questions

Question

u = 5 j , v = 6 i Find the angle between the vectors.

Answered: 1 week ago