Hi I have created an Inventory program that displays the product name, item number, how many units, and it's price and at the end displays the totals, I have to modify the program so that it will handle multiple items. Use an array
to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory.
In order to do this I have to create a method to calculate the value of the entire inventory and create another method to sort the array items by the name of the product.
Here is my code:
import java.text.NumberFormat;
public class Produce {
//initialize and load array with values
private static int[] produceNumber = new int[] {2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024};
private static String[] produceName = new String[] {"carrots","potatoe", "bananas", "tomatoe", "lettuce", "apples", "oranges", "grapes", "cherrie", "celery"};
private static int[] produceStock = new int[] {20, 50, 12, 15, 10, 30, 40, 6, 75, 8};
private static double[] producePrice = new double[] {.50,2.75,.60,1.00,1.50,2.50,3.00,1.89,2.50,1.48};
public static void DisplayOutput()
{ //Displays inventory and totals
System.out.println("Item Number\tProduce Name\tStock\tPrice\tTotal Price\n");
NumberFormat numForm = NumberFormat.getCurrencyInstance();//Displays double values as currency
double totalValue = 0;
for (int i=0; i<10; i++){
// String price = numform.format(producePrice[i]);
System.out.println(produceNumber[i]+"\t\t"+ produceName[i]+"\t\t"+produceStock[i]+"\t"+numForm.format(producePrice[i])+
"\t"+(numForm.format(produceStock[i]*producePrice[i])));
totalValue=totalValue+(produceStock[i]*producePrice[i]);
}
System.out.println("\n\nTotal Stock Value: "+numForm.format(totalValue));
}
}