In: Computer Science
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:
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:
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.
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