/*
*
*/
// Import class to format values into currency
import java.text.DecimalFormat;
/**
*
* @author Tammy
*/
public class Inventory {
// Set up an array 0f Products
int inventorySize = 30;
private Product items[] = new Product[InventorySize];
// Set formatter to format values into currency
DecimalFormat formatter = new DecimalFormat("$###,###.00");
private int InventorySize;
// Add a product to array, adds to first empty slot found
public void addProduct (Product item){
for (int i = 0; i< inventorySize; i++){
if (items[i] == null) {
items[i] = item;
return;
}
}
}
/* Loop through array and add up the total value
* Add quantity on hand and multiply by its price
* Add the value to a running total
*/
public double getTotalInvValue(){
double sumOfInventory = 0.0;
for (Product item : items) {
// Make sure there is an item
if (item != null) {
sumOfInventory += item.getItemValue();
}
}
return sumOfInventory;
}
// Prints inventory list with; name, quantity, price, and total stock value for each item.
public void printInventory() {
System.out.println("Printing items in inventory...\n");
boolean hasItems = false;
for (Product item : items) {
if (item!= null) {
hasItems = true;
System.out.println("Inventory is currently empty.\n");
}
Please let me know if you need all of the code for this assignment, as I am not sure. This is the part of the code that keeps giving me one error when I try to build the main project. Thanks for the help.

New Topic/Question
Reply



MultiQuote






|