Welcome to Dream.In.Code
Become a Java Expert!

Join 149,511 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,367 people online right now. Registration is fast and FREE... Join Now!




Inventory Program 2 Array Difficulty

 
Reply to this topicStart new topic

Inventory Program 2 Array Difficulty

gonzalez247
16 Aug, 2007 - 05:59 PM
Post #1

New D.I.C Head
*

Joined: 5 Aug, 2007
Posts: 9


My Contributions
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.
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Inventory Program 2 Array Difficulty
16 Aug, 2007 - 07:05 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
I think you might be colliding names. Call your class something else rather than Arrays because there is already a class called that in your imported package. Call it something like "Products" or "MyProducts" and see if that clears up the error.

Hope it helps.

This post has been edited by Martyr2: 16 Aug, 2007 - 07:06 PM
User is offlineProfile CardPM
+Quote Post

gonzalez247
RE: Inventory Program 2 Array Difficulty
16 Aug, 2007 - 07:55 PM
Post #3

New D.I.C Head
*

Joined: 5 Aug, 2007
Posts: 9


My Contributions
Thanks for the info but I still receive the same two errors. Would you happen to know what symbol it is looking for?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 07:38PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month