Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Page Programming Project 7: Create an inventory program Total Points (100 pts) - Due Tuesday, March 9th at 11:59 PM Overview . . Create an

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Page Programming Project 7: Create an inventory program Total Points (100 pts) - Due Tuesday, March 9th at 11:59 PM Overview . . Create an inventory program that can be used for a range of different products (cds, dvds, software, etc.). Topic(s): Using loops and if statements Arrays of objects Instantiating Objects and Creating Classes Constructors 1. Open the inventory program that was created in Project 6: Creating an inventory project 2. You want to be able to mark your products as active or discontinued. If a product is discontinued it means that the remaining stock will be the last of it, and no more orders are to be made. a) Add a Boolean instance field to your Product class called active that has a default value of true. b) Create getter/setter methods for this new field. c) Add the value of this new field to the toString() method so that the output matches the following: Item Number :3 Name : Marker Quantity in stock: 200 Price : 7.25 Product Status : Active 3. When you run the code, you get back a printed value for active as either true or false. This is not user friendly and would be better if the output stated either Active (true) or Discontinued(false) Add a ternary operator in your toString) method to achieve this. 4. Call the setter from the driver class and set the active value to false for the product object before you display the values to screen. Run and test your code 5. Create a method getinventoryValue() in the Product class that will return the inventory value for Page > of 5 5. Create a method getinventoryValue() in the Product class that will return the inventory value for each item. Use the product price multiplied by the quantity of stock to calculate the inventory value. Do not use any local variables in this method simply return the value in a single line of code. 6. Update the toString() method in the Product class to include a method call to the getinventoryValue() method that you have just created so that the output is as follows: Item Number :3 Name Marker Quantity in stock: 200 Price 7.75 Stock Value: 1550.0 Product Status : Active Page 1 of 5 CS 111B | Project #7 Spring 2021 7 Modify the ProductTester class. Ask the user to enter the number of products they wish to add. Accept a positive integer for the number of products and handle the value of zero, a) Create a variable named maxSize that can store integers. b) Create a prompt at the beginning of your main method that will instruct the user to enter the required value for the number of products they wish to store: .blodcudd Page of G 7. Modify the ProductTester class. Ask the user to enter the number of products they wish to add. Accept a positive integer for the number of products and handle the value of zero. a) Create a variable named maxSize that can store integers. b) Create a prompt at the beginning of your main method that will instruct the user to enter the required value for the number of products they wish to store: Enter the number of products you would like to add Enter 0 (zero) if you do not wish to add products: c) Use a do while loop so that the program will not continue until a valid positive value is entered. If a value less than zero is entered an error message stating "Incorrect Value enteredl" should be displayed before the user is re-prompted to enter a new value. You should not leave the loop until a value of zero or greater is entered. 8. Modify the Product Tester class to handle multiple products using a single dimensional array if a value greater than zero is entered. a) Create an if statement that will display the message "No products required!" to the console if the value of maxSize is zero. b) Add an else statement to deal with any value other than zero. c) Create a single one-dimension array named products based on the Product class that will have the number of elements specified by the user. 9. You are now going to populate the array, getting the values from the user for each field in a product object a) Inside the else statement under where you created the array write a for loop that will iterate through the array from zero to 1 less than maxSize. b) As the last input you received from the user was numeric you will need to add a statement that clears the input buffer as the first line in your for loop, c) Copy the code that you used to get input from the user for all a products fields into the for loop. This includes the name, quantity, price and item number. Page of E c) Copy the code that you used to get input from the user for all a products fields into the for loop. This includes the name, quantity, price and item number d) Add a new product object into the array using the index value for the position and the constructer that takes 4 parameters e) Use a for each loop to display the information for each individual product in the products array 10. Remove any unnecessary code that's not used in this project. 11. Save your project Page 2 of 5 CS 111B | Project #7 Spring 2021 Extra Credit (20 pts) You are now going to modify your code so that the main class will not do any processing but simply call static methods when required contentimated to the condofthe main matind called addTalentonic mathed 3 of 5 Page Spring 2021 Extra Credit (20 pts) You are now going to modify your code so that the main class will not do any processing but simply call static methods when required. a) Create a static method after the end of the main method called addTolnventory. This method will not return any values and will accept the products array and the Scanner as parameters, b) Copy the code that adds the values to the array from the main method into the new addToinventory method. c) To resolve the errors that you have in your code move the local variables required (tempNumber, tempName, tempQty, tempPrice) from the main method into the top of the addToinventory method d) Add a method call in main to the addToinventory() method where you removed the for loop from. e) Run and test your code. A Create a static method after the end of the main method called displayinventory. This method will not return any values and will accept the products array as a parameter. Remember when you pass an array as a parameter you use the class name as the data type, a set of empty square brackets and then the array name (ClassName[] arrayName), B) Copy the code that displays the array from the main method into the new displayinventory method h) Where you removed the display code from main, replace it with a method call to the displayinventory method. Remember to include the correct argument list to match the parameter list in the method you are calling Run and test your code

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

50 Tips And Tricks For MongoDB Developers Get The Most Out Of Your Database

Authors: Kristina Chodorow

1st Edition

1449304613, 978-1449304614

More Books

Students also viewed these Databases questions

Question

=+7. Who are vocal activists on this issue?

Answered: 1 week ago