This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes ArrayList advice needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ArrayList advice needed" Watch "ArrayList advice needed" New topic
Author

ArrayList advice needed

Frank Sween
Greenhorn

Joined: Feb 19, 2009
Posts: 8
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
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
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
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
And welcome to JavaRanch
Frank Sween
Greenhorn

Joined: Feb 19, 2009
Posts: 8
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
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
Try calling the methods printCardList or similar and pass a List<Card> as a parameter.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
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

Joined: Feb 19, 2009
Posts: 8
This is Kevin Sweeney, Entertainment Systems, WIT.


(sorry for bump)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ArrayList advice needed
 
Similar Threads
weird error when my jsp page uses a javabean for help
weird error when using a java bean with my jsp
Help With 5 card stud program
Exception in thread "main"
Using arrays to randomly generate images? (applet)