The assignment requires:
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 the Inventory class, array, and Inventory application. I am having trouble combining the array and Inventory application. Here are the codes I have so far.
CODE
public class Inventory1
{
private String name;//product name
private int number;//item number
private int units;//units available
private double price;//price per unit
public Inventory1 () //Default constructor
{
}//End default constructor Product
//Initialization Constructor
public Inventory1 ( String nameIn, int numberIn, int unitsIn, double priceIn)
{
setName (nameIn);
setNumber (numberIn);
setUnits (unitsIn);
setPrice (priceIn);
//setValue (valueIn);
} //End initialization constructor Product
//Declare Set/Get Methods
public void setName( String nameInput )
{
name = nameInput;
} //End method setName
public void setNumber ( int numberInput )
{
int number = numberInput;
} //End method setNumber
public void setUnits ( int unitsInput )
{
units = unitsInput;
}
public void setPrice ( double priceInput )
{
price = priceInput;
} //End method setPrice
public String getName ()
{
return ( name);
} //End method getName
public double getNumber ()
{
return ( number );
} //End method getNumber
public double getUnits ()
{
return ( units );
} //End method getUnits
public double getPrice ()
{
return ( price );
} //End method getPrice
public double InventoryValue()
{
return ( units * price );
} //End method InventoryValue
//toString()Method
//Returns a formatted String for output purposes
public String name()
{
String formatString = "Identification Number "+getNumber()+"\n";
formatString += " Product Name "+getName()+"\n";
formatString += " Units In Stock "+getUnits()+"\n";
formatString += " Unit Price "+getPrice()+"\n";
formatString += "Inventory Value "+InventoryValue()+"\n";
return formatString;
}//End name()
}//End Inventory1
CODE
import java.util.Scanner;
public class InventoryApplication
{
//main methods begins execution of application
public static void main (String args [] )
{
Scanner input = new Scanner (System.in );
Product p = new Product ( );
System.out.printf (p.toString () );
}
}//End InventoryApplication
CODE
import java.util.Arrays;
public class Arrays
{
public static void main( String args[] )
{
//Declare and initialize the inventory array
Product inventory []; //An array variable
//Size the array
inventory = new Product[3];
inventory[0] = new Product("DVD", 1, 40, 20.00);
inventory[1] = new Product("Pens", 2, 10, 3.99);
inventory[2] = new Product("Pencils", 3, 1000, 2.99);
//Sort the array
Arrays.sort( inventory );
int x = inventory[0].compareTo(inventory[1]);
System.out.println(x+"\n");
for(int i=0; i<3; i++)
System.out.println(inventory[1].toString());
}//End main
}//End Array
I am also receiving two errors for the array.
1: Arrays is already defined in this compilation unit
import java.util.Arrays;
^
18: cannot find symbol
symbol : method sort(Product[])
location: class Arrays
Arrays.sort( inventory );
Thanks for any help anyone can provide.