This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes ArrayLists and Objects. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ArrayLists and Objects." Watch "ArrayLists and Objects." New topic
Author

ArrayLists and Objects.

Ben Jones
Greenhorn

Joined: Oct 04, 2007
Posts: 16
Ok, after a *long* holiday I'm back at uni' and I've got a little Java assignment to do. I need to some classes called Cashier, OrderList and Cook (Although I'm not really concerned with Cook at the moment.) The idea is that the Cashier has a name, and when she creates an order their name, the time of the order and the order number are adding to the ArrayList. This is what I have so far:

Cashier.java


OrderList.java


Sorry if I'm doing something really obviously wrong. I know something isn't right because I don't think anything actually gets added to the array, when I run this code I get something like "OrderList@38a97b0b".

P.s. I've made this use the Runnable interface because eventually I will be using a thread to add order a new order every ~5 secs.

Dan Brownlow
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You're printing out the default toString() representation of an OrderList--that's just what it looks like.

For me the more immediate issue is naming: An OrderList isn't a list. It's an Order. I also question keeping the *actual* order list as a static member in the OrderList class, but for your purposes it's probably just fine.
Ben Jones
Greenhorn

Joined: Oct 04, 2007
Posts: 16
So are you saying I'd be better off with a class called Order that creates the Order object, etc, and adds it to the OrderList class?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

"Better off" is subjective. But no; I'm saying you'd be better off with an Order class, and a list of those orders (currently static in your class, which is, again, probably just fine for what you're doing).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: ArrayLists and Objects.