I am new to java programming and I have to write an inventory program that can hold multiple items. I have my code from week 1 but I do not know how to write in the ability to hold multiple inventory items. Can anyone help with this?
rob.sigmon.1 0 Light Poster
Recommended Answers
Jump to PostYou could use an array, matrix (multidimensional array), Vector, List, ArrayList, Collection, Map...
In my opinion, then simplest would probably be to useList<InventoryItem> inventory = new ArrayList<>();
Jump to PostYes, we can, but we'd need to know what you have done already, or at least what you know how to do. We might need to see your code, or at least the part you are having problems with.
If you need to post part of tyour code, use the …
Jump to PostYou would presumably replace
Cars product = new Cars(2479, "BMW M6", 45, 65000);
with
Cars[] products = new Cars[10]; // or however large the lot is supposed to be
You would then have to initialize each of the elements with …
Jump to PostHere's a simple example to underline what Schol-R-LEA has already said:
public class Item { // Item properties: private int _id; private String _name; // We have a constructor to setup this item: public Item(int aNumber, String aName) { _id = aNumber; _name = aName; } // …
Jump to PostThe loop to print all the Cars terminates on line 22, so it includes printing the number, but excludes the rest of the prints.
All 20 Replies
TylerD75 0 DaniWeb Newbie
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster
rob.sigmon.1 0 Light Poster
rob.sigmon.1 0 Light Poster
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster
rob.sigmon.1 0 Light Poster
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster
rob.sigmon.1 0 Light Poster
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster
rob.sigmon.1 0 Light Poster
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster
TylerD75 0 DaniWeb Newbie
rob.sigmon.1 0 Light Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
rob.sigmon.1 0 Light Poster
rob.sigmon.1 0 Light Poster
rob.sigmon.1 0 Light Poster
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster
rob.sigmon.1 0 Light Poster
pookie47 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.