• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating multiple object with multiple arraylists.  RSS feed

 
Darryn McCartney
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i am creating a tvseries object that has a contrustor in which if passes parametres of
Sting title, genre
arrayLists <string> - episodes
Arraylist <Double> - rating.

When i am creating this object

How do i create one object to hold all the game of throne episode arraylist and another object  to hold all the decter episode arraylists.
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch Darryn!

Why are you using String to model a TV episode? Strings are a terrible data type that don't really say much about what their content means. you should only use them for names or IDs. You can make a separate Episode class that contains a name and a rating field. Whatever class you have that you want to consist of episodes, be it a series, or a catalog or a TV guide, you can just compose it of lists containing objects of the Episode class.
 
Paul Clements
Ranch Hand
Posts: 99
1
Chrome Eclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryn McCartney wrote:Hi i am creating a tvseries object
Strictly speaking you are talking about creating a 'Class'. An object is an instance of a class.

Your class design is absolutely key to any code you write. Data is the key to 99.999% of program design, no matter the platform. However, in a class/object driven platform like Java it's especially so. As such you need to be absolutely clear what your data looks like before you write a line of code.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Have you got a TVSeries class and an Episode class? The list would be a field of the series class and it would contain episodes. You can have another List to contain all your series, but you need to think up a name for the class to put that in.
 
Paul Clements
Ranch Hand
Posts: 99
1
Chrome Eclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wonder if you could have:

TVSeries
Genre
Show
Episode

...or am I splitting out attributes too much i.e. blowing an attribute up into a class?
 
Junilu Lacar
Sheriff
Posts: 11493
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clements wrote:...or am I splitting out attributes too much i.e. blowing an attribute up into a class?

Depends on what kind of information exactly OP wants to track. If all he wants to track are episode titles, then why create a whole class for it? OTOH, if he wants to track the director, producer, season, run-length, guest stars, etc. for each episode, then sure, an Episode class is justified. Judging from his other field, rating, if that is a rating per episode, then I would say just the two fields of title and rating is enough to justify creating an Episode class.  Genre would probably be more appropriately defined as an enumerated constant. Show and Series seem to be synonyms; what's the difference?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!