• Post Reply Bookmark Topic Watch Topic
  • New Topic

object array  RSS feed

 
Keano Denton
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to create an sales application that has an array that holds the day of the week and the amount of sales for that day. From the user's input. Then display it back to them.

Is it possible to have an object array that holds two different primitives, i.e. a String, and a double?
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. However just to clarify: (a) String objects aren't primitives; (b) double values are indeed primitives but they can be stored in an Object array through the process known as "autoboxing".

So in other words, yes, an Object array can contain a String and a double value as its two entries. But it usually isn't a good idea. Unless you're working on an assignment which specifically requires you to use an array for this, you'd probably be better off with a DailySales class with two attributes, namely day-of-week and sales-amount.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like what you might actually want is a class that combines the day and the sales for that day. Something like
Then you can have an array of instances of that class. Each array entry will contain both values.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!