This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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:
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.
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.
Joined: Oct 04, 2007
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?
"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).