Results 1 to 4 of 4
- 03-25-2009, 06:29 PM #1
Member
- Join Date
- Mar 2009
- Location
- New Jersey
- Posts
- 2
- Rep Power
- 0
Using arrayList to store data from one class to another.
Hi i am taking my first java course and i have been stuck for a couple of days on a certain assignment. What i want to do is send string type data from one class and store it in a arrayList of another class. Also the data that i am sending over is in 3 categories. The assignment is to store an item from a store. the three categories are item name, item department, and item cost. I would be sending them from the item class to the shopping cart class.
- 03-25-2009, 07:03 PM #2
There is usually more than one way to do things like this.
You could make up a data store class:
Java Code:class ShoppingCart { List<ItemStore> items = new ArrayList<ItemStore>(); public void addItem(ItemStore store) { items.add(store); } class Item { ShoppingCart cart; private void addSelection() { ItemStore item = new ItemStore("ClearCut", "DVD", 10.00); cart.addItem(item); } } class ItemStore { String name; String itemDepartment; double cost; }
- 03-26-2009, 01:39 PM #3
Member
- Join Date
- Mar 2009
- Location
- Schenectady, NY
- Posts
- 11
- Rep Power
- 0
The above post is a great summary. The idea is to create classes (beans) of each of the "nouns" you're working with (ie., the item and the shopping cart) with properties describing them (name, cost, items). Then write methods that "do" the things you need to do with the classes, such as add an item to the cart.
SoftSlate Commerce Java Shopping Cart
www.softslate.com
- 03-28-2009, 05:02 AM #4
Member
- Join Date
- Mar 2009
- Location
- New Jersey
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
help me to store data in a class
By neeraj.singh in forum New To JavaReplies: 2Last Post: 08-06-2009, 08:31 AM -
how to store the data in data base
By eclipse3.4ide in forum New To JavaReplies: 5Last Post: 02-03-2009, 04:25 AM -
how to store an ArrayList<string> into cookies?
By perplexingtrax in forum Java ServletReplies: 7Last Post: 01-12-2009, 12:30 AM -
How to create folder(s) and store data?
By Grom in forum New To JavaReplies: 2Last Post: 08-20-2008, 09:01 AM -
how to use btree to store data
By fred in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks