Compiling complication with objects

I can't seem to understand why this isn't compiling. Complicat

Page 1 of 1

5 Replies - 543 Views - Last Post: 02 March 2009 - 05:07 PM Rate Topic: -----

#1 Seraneth  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-March 09

Compiling complication with objects

Posted 01 March 2009 - 11:14 PM

Hey guys,

I am a learning java, I am not very experienced but do enjoy programming. I am using the BlueJ compiler (which i have grown to like) and I can't seem to get this code to compile. The error is.....

"cannot find symbol - method add(CardGroup)"

i posted my code below. The error occurs in the second add() method (the one that passes a CardGroup parameter). I have been working at this code for a long while now and just don't seem to understand why I can't fix this error. I want to understand why I can't make this work so if you wouldn't mind explaining what my error is I would appreciate it.

Here is a bit of my logic.
What I want to do is be able to pass a set of cards (numerous) into the method and add them to my the current objects cards. From what I understand, if I had two objects and one of them was going to give the other objects his cards, this method would execute that. So my thought was to just use the add() or addAll() built in function for arrays. I have tried numerous things on this method, but I have gotten to the point where it is doing more harm than good playing with it. Also not, some of the other code is not complete, and that is intentional, once i get this method to work, i can finish the rest. hence the reason that half of it is void or noted out.

Thanks for your help guys, I appreciate it.
import java.util.*;
public class CardGroup
{
int R = 0;
String Stringing;
Card Spades;
Card Hearts;
Card Clubs;
Card Diamonds;
Card Last;

ArrayList<Card> Group = new ArrayList<Card>();

	public CardGroup()
	{

	}

	public void newDeck()
	{
		for(int j = 1; j <= 13; j++)
		{
			Spades = new Card(j , Suit.spades);
			Group.add(Spades);

		}
		
		for(int j = 1; j <= 13; j++)
		{
			Hearts = new Card(j , Suit.hearts);
			Group.add(Hearts);

		}
		
		for(int j = 1; j <= 13; j++)
		{
			Clubs = new Card(j , Suit.clubs);
			Group.add(Clubs);
			//Clubs.toString()
	 
		}
		
		for(int j = 1; j <= 13; j++)
		{
			Diamonds = new Card(j , Suit.diamonds);
			Group.add(Diamonds);
	   
		}
	 /* for(int k = 0; k < 52; k++)
		{
			System.out.println(Deck.get(k));
		}*/
	}
	
	public void add(Card c)
	{
		Last = c;
		Group.add©;

	}
	

	
	public void add(CardGroup set )
	{

		for(int i = 0; i < Group.size(); i++)
		{
		Group.add(set);
		}

	}
	
	
	public int count()
	{
		return Group.size();
	}
	
	public void get(int index)
	{
  //	  return Group.get(index); of type Card
	}
	
	public void getLast()
	{
	 //return Card type
	}
	
	public Card draw()
	{
		return null;

	/*	int Random = (int)Math.random() * 52 + 1;
		if(Random > Deck.size()) Random = Random - R;
		Deck.remove(Random);
		Group.add(Deck.get(Random));
		R++;		
		return Deck.get(Random);*/
	}
	








}

This post has been edited by Seraneth: 01 March 2009 - 11:21 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Compiling complication with objects

#2 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,900
  • Joined: 25-October 06

Re: Compiling complication with objects

Posted 01 March 2009 - 11:38 PM

for a start you have a problem with
	public void add(Card c)
	{
		Last = c;
		Group.add©;

	}


should be
	public void add(Card c)
	{
		Last = c;
		Group.add(c);	// << fixed this

	}


Was This Post Helpful? 0
  • +
  • -

#3 Seraneth  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-March 09

Re: Compiling complication with objects

Posted 01 March 2009 - 11:41 PM

Huh, thats odd, It says i have

Group.add( c );

If it take out the spaces it looks like ©. odd.

This post has been edited by Seraneth: 01 March 2009 - 11:42 PM

Was This Post Helpful? 0
  • +
  • -

#4 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,900
  • Joined: 25-October 06

Re: Compiling complication with objects

Posted 02 March 2009 - 12:43 AM

View PostSeraneth, on 2 Mar, 2009 - 05:41 AM, said:

Huh, thats odd, It says i have

Group.add( c );

If it take out the spaces it looks like ©. odd.

sounds like you are using wordprocessing package like MS Word - use a simpler test editor such as notepad or an IDE such as Code::Blocks

otherwise try puttering spaces around the c
Group.add( c );


This post has been edited by horace: 02 March 2009 - 12:44 AM

Was This Post Helpful? 0
  • +
  • -

#5 Seraneth  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 01-March 09

Re: Compiling complication with objects

Posted 02 March 2009 - 12:47 AM

I still can't seem to figure it out. All I need to do is make it so that I can have to objects created, and be able to pass the "group" from one to the other. The parameter seems correct, but for some reason, the "set" i pass through doesn't seem to inherit the add() or addAll() methods that ArrayList can use.

	public void add(CardGroup set )
	{

		for(int i = 0; i < Group.size(); i++)
		{
		Group.add(set);
		}


Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Compiling complication with objects

Posted 02 March 2009 - 05:07 PM

View PostSeraneth, on 1 Mar, 2009 - 11:47 PM, said:

I still can't seem to figure it out. All I need to do is make it so that I can have to objects created, and be able to pass the "group" from one to the other. The parameter seems correct, but for some reason, the "set" i pass through doesn't seem to inherit the add() or addAll() methods that ArrayList can use.

	public void add(CardGroup set )
	{

		for(int i = 0; i < Group.size(); i++)
		{
		Group.add(set);
		}


Use lower case letter to start your variable name it is confusing

Group is an ArrayList of Cards
you cannot add a CardGroup to it.....
may be
	public void add(CardGroup set )
	{

		for(int i = 0; i < set.Group.size(); i++)
		{
		Group.add(set.get(i));
		}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1