I have to assignment which includes the following: Modify the Inventory Program so the application can 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.
· Create a method to calculate the value of the entire inventory.
· Create another method to sort the array items by the name of the product.
I have tried so far this is what I have;
should display the value of the entire inventory.
· Create a method to calculate the value of the entire inventory.
· Create another method to sort the array items by the name of the product.
I have tried so far this is what I have;
Code:
1. import java.text.NumberFormat; 2. 3. public class Produce { 4. 5. //initialize and load array with values 6. 7. private static int[] produceNumber = new int[] {2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024}; 8. 9. 10. private static String[] produceName = new String[] {"carrots","potatoe", "bananas", "tomatoe", "lettuce", "apples", "oranges", "grapes", "cherrie", "celery"}; 11. 12. 13. private static int[] produceStock = new int[] {20, 50, 12, 15, 10, 30, 40, 6, 75, 8}; 14. 15. 16. 17. private static double[] producePrice = new double[] {.50,2.75,.60,1.00,1.50,2.50,3.00,1.89,2.50,1.48}; 18. 19. 20. public static void DisplayOutput() 21. 22. { //Displays inventory and totals 23. 24. System.out.println("Item Number\tProduce Name\tStock\tPrice\tTotal Price\n"); 25. 26. NumberFormat numForm = NumberFormat.getCurrencyInstance();//Displays double values as currency 27. 28. double totalValue = 0; 29. 30. for (int i=0; i<10; i++){ 31. 32. // String price = numform.format(producePrice[i]); 33. 34. System.out.println(produceNumber[i]+"\t\t"+ produceName[i]+"\t\t"+produceStock[i]+"\t"+numForm.format(producePrice[i])+ 35. 36. "\t"+(numForm.format(produceStock[i]*producePrice[i]))); 37. 38. totalValue=totalValue+(produceStock[i]*producePrice[i]); } 39. System.out.println("\n\nTotal Stock Value: "+numForm.format(totalValue)); 40.} 41.} 42. 43.// Inventory Part 2 July 17, 2008 44. 45. function setObject (produceName, produceNumber, produceStock, producePrice){ 46. myObjectArray[objectArrayIndex++] = new ownObject (produceName, produceNumber, produceStock, producePrice); 47. 48. } 49. 50. 51. 52. var objectArrayIndex =0; 53. var myObjectArray = new Array(); 54. 55. SetObject ("carrots","potatoe", "bananas", "tomatoe", "lettuce", "apples", "oranges", "grapes", "cherrie", "celery"); 56. SetObject (2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024); 57. SetObject (20, 50, 12, 15, 10, 30, 40, 6, 75, 8); 58. SetObject (.50,2.75,.60,1.00,1.50,2.50,3.00,1.89,2.50,1.48); 59. 60. function showArray (produceName, produceNumber, produceStock, producePrice) { 61. 62. document.write (produceName + ':');
Comment