Results 1 to 14 of 14
- 05-26-2011, 03:03 AM #1
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
Building an inventory program that uses an array but has string values as well as int
Hello all. I am trying to build a program that stores inventory for selected products and must use an array. My problem is that the inventory is supposed to show the product name, item number, department, units in stock and price. I think I have figured out how to create an array using just integers but I need string values such as the name and department it falls under. My instructor says this is possible using just one array, however, I don't think it matters if I do use two arrays, or even five if needed for the products in inventory. I would rather only use one array but this week I need to modify the program so it shows off more than one product (and its details listed above). Anyone have any ideas that I could use just one array with the integer values but still display the name and department of the products?
- 05-26-2011, 03:49 AM #2
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Is this an assignment? You might want to take a look at 2D array.
Here is a tutorial in java about JTable which uses 2D array to fill data.
How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
- 05-26-2011, 08:07 AM #3
Senior Member
- Join Date
- Feb 2011
- Location
- Georgia, USA
- Posts
- 122
- Rep Power
- 0
can you make a product class that has all those fields and then make an array of products?
- 05-26-2011, 09:53 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
- 05-26-2011, 07:41 PM #5
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
I could use objects in the array and then have all these details i need in the objects. I also need to have the program do a total value of the inventory (units in stock of each camera * price), is this possible using objects from the array?
- 05-26-2011, 08:13 PM #6
Yes, that would work.is this possible using objects from the array?
- 05-26-2011, 09:43 PM #7
Is Product and Inventory season early this year? It's usually around September.
db
- 05-27-2011, 02:21 AM #8
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
Ok, so I am really REALLY lost here. I am trying to start over again. Let's say for my inventory program to call up an array of objects class that I create, the product, can I use an int array to call up these objects? Like this
int array[] = { product1, product2 }
and in my other product class I need to declare these
product1 = (productName, productItemNumber, etc.)
product2 = (pruductName, productItemNumber, etc.)
Can I assign these to the integers 1 and 2 in the int array? I need this program to display my product's details that have double and string values.
I am so lost and my instructor only emails me very late and I was supposed to turn this in today
Can anyone help me get started here? I am looking at this wrong or approaching this the wrong way?
- 05-27-2011, 02:57 AM #9
You should look in the Java Tutorial about arrays:
Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
The syntax for creating an array is:
<THE TYPE>[] aName = new <THE TYPE>[<nbr of elements>];
Where <THE TYPE> is the type of the data held in the array. int is a type, String is a type. Or it could be a class that you define.
To get one of the elements of an array use the syntax: aName[<index for element]. That will return the element which will be of <THE TYPE> data type. For example:int, String, your class....
Before worrying about putting your class in an array, get a design for your class. What data will it hold and how will you put data into it and get data from it.
- 05-27-2011, 06:49 AM #10
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
@OP - It is hard to suggest when you do not see the logic or what you are trying to do.
Here is an example of 2D Array which holds a group of item. Each item have their related details such as manufacturer, price and current stock
Can you post some code that is related on your problem?Java Code:Object[][] anArray2d = new Object[][]{ {"JM019", "DELL", new Double(1049.55), new Integer(165)}, //--| {"SH2448", "AOC", new Double(899.99), new Integer(98)}, // | {"EQ755", "ACER", new Double(127.34), new Integer(134)}, // |>>> ROW {"EQ764", "ACER", new Double(127.34), new Integer(256)}, // | {"KG875", "COBY", new Double(127.34), new Integer(134)} //--| };
- 05-27-2011, 08:59 AM #11
- 05-27-2011, 09:47 AM #12
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Why yuck?
mine0926
- 05-27-2011, 10:18 AM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Because the OP has said:
"I could use objects in the array and then have all these details i need in the objects."
Which means they can create a class to hold the data, so using an array to hold that class data is a complete hack.
Or, put another way...yuck.
- 05-27-2011, 10:48 AM #14
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Similar Threads
-
Problem with String Building
By Albert in forum New To JavaReplies: 2Last Post: 04-30-2012, 12:49 AM -
Sorting string Array Values
By Zerpol in forum New To JavaReplies: 1Last Post: 01-14-2011, 07:08 AM -
My Inventory Program
By ladykrimson in forum New To JavaReplies: 28Last Post: 11-01-2010, 09:06 PM -
Help with Inventory Program, Please
By NewKidjava in forum New To JavaReplies: 4Last Post: 08-21-2009, 11:09 AM -
Inventory program
By Nexcompac in forum New To JavaReplies: 3Last Post: 07-27-2007, 05:51 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks