Storing a list of information of different types of data in an Array

Discussion in 'Java' started by Paperkut, Oct 24, 2009.

  1. Paperkut

    Paperkut New Member

    Joined:
    Oct 24, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    partNo Description quantity i
    123 Shampoo 24
    224 Blue Biros 56
    225 Red Biros 32
    324 Cheese 15
    369 Shower Gell 8
    145 Green Olives 35


    Hello, i am new to this forums and i have a problem with my project. I have to code an inventory control system for warehouse. This is the list of information i need to store in a class, but i just can't figure out how. Any help appreciated
     
  2. devunion

    devunion New Member

    Joined:
    Sep 26, 2008
    Messages:
    19
    Likes Received:
    2
    Trophy Points:
    0
    Something like that:

    Code:
    public class Inventory {
        private long partNo;
        private long description;
        private long quantity;
    
        public Inventory() {
        }
    
        public Inventory(long partNo, long description, long quantity) {
            this.partNo = partNo;
            this.description = description;
            this.quantity = quantity;
        }
    
        public long getPartNo() {
            return partNo;
        }
    
        public void setPartNo(long partNo) {
            this.partNo = partNo;
        }
    
        public long getDescription() {
            return description;
        }
    
        public void setDescription(long description) {
            this.description = description;
        }
    
        public long getQuantity() {
            return quantity;
        }
    
        public void setQuantity(long quantity) {
            this.quantity = quantity;
        }
    }
    
    Now you can create new object and att it to your array:

    Code:
            Inventory[] inventories = new Inventory[10];
            inventories[0] = new Inventory(123, "Shampoo", 24);
    
    BTW it will be better to use lists instead of arrays. For example, ArrayList.

    PS. Also you need to find some Java book :). It will be helpful.
     
    Last edited by a moderator: Nov 8, 2009
  3. SyferZookie

    SyferZookie New Member

    Joined:
    Nov 6, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    College Student , taking up IT
    Location:
    Philippines
    i think thsis are methods right?
    or classes?

    god damn, every time goes by i forgot the basic codes damnit.
    need to drink or take a medicine for anti amnesia. :P
     
  4. Michal Right

    Michal Right Banned

    Joined:
    Mar 21, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Analyst
    Location:
    UK
    Home Page:
    http://www.urdirect.co.uk/
    It looks nice to me. Just the content arrangement, make some improvements.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice