This week's book giveaway is in the iOS forum.
We're giving away four copies of Classic Computer Science Problems in Swift and have David Kopec on-line!
See this thread for details.
Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList advice needed  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OKay so i have assignment called mystery calculator, it seems simple enough but im stuck on how to arrange it..
What initially has to be done is that i have 6 'cards' populated with a series of numbers which cant be hardcoded ..

what i have so far is


My Question is: should i have a separate class called Card and instantiate the 6 arraylists there? or should i have one arraylist in a Card class and one araylist in Calculator class and somehow do it like that? im new to this and relly could do with some help much appreciate
 
Marshal
Posts: 58829
179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Difficult to be sure, and there is a very nice distinction between some of your options.
I don't know the full details about having Lists in different classes, but the idea of one List in one class and another List in another class seems a bit suspect to me.
The difference between what you have and a Card class appears slight, but I suspect you will get better OO design, a minor consideration, and better marks, a major consideration, if you can create a Card class and keep your 6 Lists in 6 Card objects.

I presume you don't mind that some numbers are going into several cards?
You realise that i % 16 can never be > 15, which means you might be able to simplify several of your if conditions.
 
Campbell Ritchie
Marshal
Posts: 58829
179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
Frank Sween
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thanks for reply,

yea my major consideration is good marks, just starting programming and liking it..
So I went and made a 'Card' class and it works but...... I have a feeling my code is kindof bloated and im trying to cut down on the amount of code (this is what lecturers are telling us to do),

heres what I have so far, this is my Calculator class


And here is my Card class


What i want to know is any way of lessening this code? Is there a way I can get rid of all those separate printCard*() methods?

again any help is greatly appreciated
 
Campbell Ritchie
Marshal
Posts: 58829
179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try calling the methods printCardList or similar and pass a List<Card> as a parameter.
 
Campbell Ritchie
Marshal
Posts: 58829
179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the long block of repeated print statements can probably be condensed similarly. But I am too tired to work out how just now
 
Frank Sween
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is Kevin Sweeney, Entertainment Systems, WIT.


(sorry for bump)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!