Question

In: Computer Science

Java program code: InventoryManager For this assignment, you will be creating an inventory manager for a...

Java program code: InventoryManager

For this assignment, you will be creating an inventory manager for a store that sells vegetables. The inventory will be managed using arrays.

The required name for the project is InventoryManager.
The required name for the Java file is InventoryManager.java.
The required main class name is InventoryManager.

Part 1: Planning the store

Decide the name of your store. Place this name in a constant called STORE_NAME.
As soon as the program starts, display a greeting to the user to let them that they have begun using the inventory management app for this store.
Then, perform the following:

  1. Create an array called items for a maximum of 5 items in your store. The items in the array should be onion, broccoli, carrot, zucchini, and cucumber.
  2. Create a second array called quantities to store the quantity of each of the five items.
    Using a loop, have the user enter the quantity of each of the five items, and make sure each value of quantity is inserted into quantities array at the appropriate index (the same index as the item in the items array).
    For this step, we will assume the user will only enter an integer, but you should validate their input to make sure they enter a value greater than or equal to zero. If they do not enter an integer greater than or equal to zero, then you must prompt them to enter the value again (until they get it right).
    HINT: Consider using another loop to have them enter the quantities.
  3. Create a third array called prices to store the price of each of the five items. Using a similar process to Step 2, have the user enter the price of each of the five items and make sure they are stored in the prices array at the appropriate index. Just like Step 2, you should make sure the user-entered prices are greater than or equal to 0. Otherwise, they should repeat entering the value until they get it correct.

The following table is just one example of the values that might populate the three arrays. Each index represents one single item.

INDEX 0 1 2 3 4
items array onion broccoli carrot zucchini cucumber
quantities array 12 4 3 56 30
prices array 1.52 0.53 1.25 1.34 2.32


NOTE: Apart from the items array, these are just example values. Because the user is required to enter these values, values in quantities and prices could be anything.

If we were to determine the quantity of our carrots, we would first find that "carrot" is located at index 2 in items, so we would retrieve the value in quantities at index 2, which is a quantity of 3. To find the price, we would retrieve the value at index 2 of prices, which is 1.25.

Make sure you use the appropriate datatype for each array (int? double? String?)

All of the previous directions take place only at the beginning of the program. You can think of it as the set up for the main part of the program. Once done, the user will be taken into Part 2 of this assignment.

Part 2: Operating the InventoryManager

Display to the user the possible operations on the inventory and prompt him/her to choose one. The user should select the option by entering its number. Every time the user completes one of the operations (except for Exit), the user should be taken back to this screen where they can choose from this list again. If Exit is selected, the user should be given a message thanking them for using the program, and then the program should be properly closed. Do not use System.exit() to close the program. You must exit the program by exiting the loop itself.

There are 5 possible operations:

1. Print inventory
2. Check for low inventory
3. Highest and lowest inventory value items
4. Total inventory value
5. Exit

1. Print inventory

This operation prints all the inventory items, with each item shown in the following format:

Item: ITEM-NAME
Quantity: ITEM-QUANTITY
Price: ITEM-PRICE
Total value: TOTAL-VALUE

ITEM-NAME should be replaced by the name of the item.
ITEM-PRICE should be replaced by the price of the item.
TOTAL-VALUE should be replaced by the total price if someone were to purchase the entire stock of items.

Make sure your output appears exactly like the format above. You should print the information for all five items in an efficient way (using a loop).

Once this is done, the user should be allowed to select one of the five options from the original menu.

2. Check for low inventory

This operation checks for items that have a quantity of less than 5, then prints them in the same format as in option 1.

If there is no such item whose quantity is less than 5, then display a message that explains that to the user.

Once this is done, the user should be allowed to select one of the five options from the original menu.

3. Highest and lowest inventory value items

This operation finds the following two items:

  • The item with the highest inventory value.
  • The item with the lowest inventory value.

Remember that the total inventory value is the value of the whole stock of the inventory item combined, which would be equal to the quantity multiplied by the price.

If two or more items have a matching inventory value and they are either the highest or lowest, then you only need to display one of them.

Display the highest and lowest inventory value items in the same way as option 1.

Once this is done, the user should be allowed to select one of the five options from the original menu.

4. Total inventory value

This is the total value of ALL items in the store, taking into account the quantity of each item. Display this value to the user.

Once this is done, the user should be allowed to select one of the five options from the original menu.

5. Exit

If selected, the user should be given a message thanking them for using the program, and then the program should exit. Do not use System.exit() to exit the program. You must exit the program by logically ending the loop.

Requirements

When this program runs, it should be obvious to the user the values they are seeing. Include all units when displaying values. For example, when displaying dollar values, make sure you include a dollar sign ($). You do not need to worry about making two decimal digits show when displaying dollar values. For example, it's okay to display $4.5 instead of $4.50.

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// InventoryManager.java

import java.util.Scanner;

public class InventoryManager {

   public static void main(String[] args) {
       //Declaring variables
       int choice;
       int size=5;
       String items[]={"onion","broccoli","carrot","zucchini","cucumber"};
       int quantities[]={12,4,3,56,30};
       double prices[]={1.52,0.53,1.25,1.34,2.32};
       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);
      
       /* This while loop continues to execute
       * until the user chooses choice 5
       */
       while(true)
       {
           //displaying the menu
           System.out.println("\n1. Print inventory");
           System.out.println("2. Check for low inventory");
           System.out.println("3. Highest and lowest inventory value items");
           System.out.println("4. Total inventory value");
           System.out.println("5. Exit");
           //getting the choice entered by the user
           System.out.print("Enter Choice :");
           choice=sc.nextInt();
           switch(choice)
           {
           case 1:{
               displayInventory(items,quantities,prices);
               continue;
           }
           case 2:{
               displayLowInventory(items,quantities,prices);
               continue;
           }
           case 3:{
               int minIndx=getHighestValue(quantities,prices);
               int maxIndx=getLowestValue(quantities,prices);
               System.out.println("Highest Inventory value Item :"+items[maxIndx]);
               System.out.println("Lowest Inventory value Item :"+items[minIndx]);
              
               continue;
           }
           case 4:{
               System.out.println("Total value: $"+totalInventoryVal(quantities,prices));
               continue;
           }
           case 5:{
              
               break;
           }
           default:{
               System.out.println("** Invalid Choice **");
               continue;
           }
           }
           break;
       }


   }

   private static int getLowestValue(int[] quantities, double[] prices) {
       double min=quantities[0]*prices[0];
       double val=0;
       int minIndx=0;
       for(int i=0;i<quantities.length;i++)
       {
           val=quantities[i]*prices[i];
           if(min>val)
           {
               min=val;
               minIndx=i;
           }
       }
       return minIndx;
   }

   private static int getHighestValue(int[] quantities, double[] prices) {
       double max=quantities[0]*prices[0];
       double val=0;
       int maxIndx=0;
       for(int i=0;i<quantities.length;i++)
       {
           val=quantities[i]*prices[i];
           if(max<val)
           {
               max=val;
               maxIndx=i;
           }
       }
       return maxIndx;
   }

   private static void displayLowInventory(String[] items, int[] quantities,
           double[] prices) {
       int flag=0;
       for(int i=0;i<items.length;i++)
       {
           if(quantities[i]<5)
           {
               flag=1;
               System.out.println("\nItem: "+items[i]);
               System.out.println("Quantity: "+quantities[i]);
               System.out.println("Price: $"+prices[i]);  
           }
          
       }
      
       if(flag==0)
       {
           System.out.println("** No Low Inventory Items **");
       }
      
   }

   private static void displayInventory(String[] items, int[] quantities,
           double[] prices) {
       for(int i=0;i<items.length;i++)
       {
           System.out.println("\nItem: "+items[i]);
           System.out.println("Quantity: "+quantities[i]);
           System.out.println("Price: $"+prices[i]);
          
       }
       System.out.println("Total value: $"+totalInventoryVal(quantities,prices));
      
   }

   private static double totalInventoryVal(int[] quantities, double[] prices) {
       double tot=0;
       for(int i=0;i<quantities.length;i++)
       {
           tot+=quantities[i]*prices[i];
       }
       return tot;
   }

}
__________________________

Output:


1. Print inventory
2. Check for low inventory
3. Highest and lowest inventory value items
4. Total inventory value
5. Exit
Enter Choice :1

Item: onion
Quantity: 12
Price: $1.52

Item: broccoli
Quantity: 4
Price: $0.53

Item: carrot
Quantity: 3
Price: $1.25

Item: zucchini
Quantity: 56
Price: $1.34

Item: cucumber
Quantity: 30
Price: $2.32
Total value: $168.75

1. Print inventory
2. Check for low inventory
3. Highest and lowest inventory value items
4. Total inventory value
5. Exit
Enter Choice :2

Item: broccoli
Quantity: 4
Price: $0.53

Item: carrot
Quantity: 3
Price: $1.25

1. Print inventory
2. Check for low inventory
3. Highest and lowest inventory value items
4. Total inventory value
5. Exit
Enter Choice :3
Highest Inventory value Item :broccoli
Lowest Inventory value Item :zucchini

1. Print inventory
2. Check for low inventory
3. Highest and lowest inventory value items
4. Total inventory value
5. Exit
Enter Choice :4
Total value: $168.75

1. Print inventory
2. Check for low inventory
3. Highest and lowest inventory value items
4. Total inventory value
5. Exit
Enter Choice :5

_______________Could you plz rate me well.Thank You


Related Solutions

PLEASE CODE IN JAVA In this assignment you will write a program in that can figure...
PLEASE CODE IN JAVA In this assignment you will write a program in that can figure out a number chosen by a human user. The human user will think of a number between 1 and 100. The program will make guesses and the user will tell the program to guess higher or lower.                                                                   Requirements The purpose of the assignment is to practice writing functions. Although it would be possible to write the entire program in the main function, your...
Could you give some sample Java code of creating a program where users are prompt to...
Could you give some sample Java code of creating a program where users are prompt to determine how many exams they have taken then it is prompt that they have to enter their test scores and gives the sum of all their test scores? You should have to use looping
The goal of Java program implemented as part of this assignment is to build an Inventory...
The goal of Java program implemented as part of this assignment is to build an Inventory Management System, from here on referred to as IMS, for a bookstore. You will need to do the following tasks: Requirement-1 – Create 3 different Arrays (15 pts) (a) Create an array named items that will hold the following item names (strings) - Pen - Pencil - Eraser - Marker - Notepad (b) Create a second array named quantity, that will hold corresponding quantities...
For this assignment, you will modify existing code to create a single Java™ program named BicycleDemo.java...
For this assignment, you will modify existing code to create a single Java™ program named BicycleDemo.java that incorporates the following: An abstract Bicycle class that contains private data relevant to all types of bicycles (cadence, speed, and gear) in addition to one new static variable: bicycleCount. The private data must be made visible via public getter and setter methods; the static variable must be set/manipulated in the Bicycle constructor and made visible via a public getter method. Two concrete classes...
Java code for creating an Inventory Management System of any company - designing the data structure(stack,...
Java code for creating an Inventory Management System of any company - designing the data structure(stack, queue, list, sort list, array, array list or linked list) (be flexible for future company growth Java code for creating an initial list in a structure. Use Array (or ArrayList) or Linkedlist structure whichever you are confident to use. - Implement Stack, Queue, List type structure and proper operation for your application. Do not use any database. All data must use your data structures....
Assignment Content Resource: ****************************CODE PASTED BELOW******************************* For this assignment, you will develop Java™ code that relies...
Assignment Content Resource: ****************************CODE PASTED BELOW******************************* For this assignment, you will develop Java™ code that relies on localization to format currencies and dates. In NetBeans, copy the linked code to a file named "Startercode.java". Read through the code carefully and replace all occurrences of "___?___" with Java™ code. Note: Refer to "Working with Dates and Times" in Ch. 5, "Dates, Strings, and Localization," in OCP: Oracle® Certified Professional Java® SE 8 Programmer II Study Guide for help. Run and debug...
Using JAVA and NETBEANS Assignment Content For this assignment, you will develop "starter" code. After you...
Using JAVA and NETBEANS Assignment Content For this assignment, you will develop "starter" code. After you finish, your code should access an existing text file that you have created, create an input stream, read the contents of the text file, sort and store the contents of the text file into an ArrayList, then write the sorted contents via an output stream to a separate output text file. Copy and paste the following Java™ code into a JAVA source file in...
For this assignment you will be creating a basic Hotel Reservation System. The program must meet...
For this assignment you will be creating a basic Hotel Reservation System. The program must meet the following guidelines: User can reserve up to 3 rooms at a time Your program will need to loop through to continue to ask needed questions to determine cost. Room rates (room variants): Suite $250 2 Queens $150 1 King $175 Ocean view add $50 Fridge for Room $25 Pets additional $50 Sales tax rate will be 5.5% Your program will show out the...
Java. You are creating a 'virtual pet' program. The pet object will have a number of...
Java. You are creating a 'virtual pet' program. The pet object will have a number of attributes, representing the state of the pet. You will need to create some entity to represent attributes in general, and you will also need to create some specific attributes. You will then create a generic pet class (or interface) which has these specific attributes. Finally you will make at least one subclass of the pet class which will be a specific type of pet,...
For this assignment you will write a Java program using a loop that will play a...
For this assignment you will write a Java program using a loop that will play a simple Guess The Number game. Create a new project named GuessANumber and create a new Java class in that project named GuessANumber.java for this assignment. The program will randomly generate an integer between 1 and 200 (including both 1 and 200 as possible choices) and will enter a loop where it will prompt the user for a guess. If the user has guessed the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT