public class InventoryManager { /** * to display total inventory * * @param item
ID: 3770542 • Letter: P
Question
public class InventoryManager {
/**
* to display total inventory
*
* @param items
*/
public static void printInventory(Item items[]) {
System.out.println("***Total Inventory***");
System.out.println("Name Quantity Price Per Unit");
for (int i = 0; i < 5; i++) {
Item item = items[i];
System.out.println(item.getName() + " " + item.getQuantity()
+ " " + item.getPrice_per_unit());
}
}
/**
* to display inventory where quantity less than 5
*
* @param items
*/
public static void checkLowInventory(Item items[]) {
System.out.println("***Low Inventory***");
System.out.println("Name Quantity Price Per Unit");
boolean flag = true;
for (int i = 0; i < 5; i++) {
Item item = items[i];
if (item.getQuantity() < 5) {
System.out.println(item.getName() + " " + item.getQuantity()
+ " " + item.getPrice_per_unit());
flag = false;
}
}
if (flag) {
System.out.println("No items Found");
}
}
}
Write a class method called totalInventoryValue which takes an Array of Items as its parameter. This method computes the total value of the current inventory using the quantity and price per unit information, and prints that total value to the console.
Explanation / Answer
Here is the method you asked me for:
public static void totalInventoryValue(Item items[]) {
double sum = 0;
for(int i = 0; i < 5; i++) {
Item item = items[i];
sum += item.getQuantity() * item.getPrice_per_unit();
}
System.out.println("Total Inventory Value: "+sum);
}
If you have any further queries, just get back to me.....
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.