QuestionQuestion

Program:

Take another look at the Item class we created in lab 11.

 Start with the items created in lab 11 including three instance variables, an accessor and mutator/modifier for each, and two constructors.
 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. Sell some 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.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/*
*   Project 5
*   Program Description - Create an item class and an ItemDriver to utilize the class
*                         Provide the user with a list of options for creationg and interacting with Item objects.      
*   Author:
*   Date:
*   Filename:   ItemDriver.java
*/


//import statements
import java.util.*;   

// class beginning
class ItemDriver {
public static void main(String[] args ) {
   
    Scanner keyboard = new Scanner(System.in);
    Item[] anArray = new Item[10];
    int userChoice;
    boolean print;
    boolean add;
    boolean found;
    String description;
   
    boolean endProgram = false;
   
    while (endProgram == false) {
      
      System.out.println("Please select what you would like to do:");
      System.out.println("1. List all items");
      System.out.println("2. List the items that need to be ordered");
      System.out.println("3. Add an item to the inventory");
      System.out.println("4. Report total inventory cost");
      System.out.println("5. Report item that is worth the most");
      System.out.println("6. Sell some of an item");
      System.out.println("7. Remove an item from list");
      System.out.println("8. Clear list");
      System.out.println("9. End program");
      System.out.println();...

By purchasing this solution you'll be able to access the following files:
Item.java, ItemDriver1.java, ItemDriverOUTPUT1.png, ItemDriverOUTPUT2.png, ItemDriverOUTPUT3.png and ItemDriverOUTPUT4.png.

$40.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats