Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Default Constructor issues

$
0
0
I've been staring at this for hours, and I believe I'm probably over thinking this but now I am just completely stuck.
I'm attempting to create a default constructor with all 52 cards. I have a default Card constructor with one card assigned a face and a suit using the enum. I just recently created what I though would work, and then after getting excited it is still throwing out an error. Just looking for someone to point me in the right direction. I'll try to put all my code that is relevant to the issue. Thanks

public Deck() //default constructor
	{
		
		for(int i=0;i<deck.length;i++)
		{
			for(Face f:Face.values())
			{
				for(Suit s:Suit.values())
				{
					deck[i].setCard(f,s);//I would think would set all 52 instances with all of the card types
										  //but this has an error
					
					
				}
			}
		}
	}


My default constructor attempting to make the deck of cards.
Card[] deck = new Card[52];


My array of the Card class used in the Deck class with the constructor Deck()
public class Card
{
	private Face face = Face.Ace;
	private Suit suit = Suit.Hearts;
	
	public Card()
	{
		face = Face.Ace;
		suit = Suit.Hearts;
	}


My Card class and the default constructor
public void setCard(Face f,Suit s)
	{
		this.face =f;
		this.suit =s;
	}

private static void showDeck()//shows entire deck of cards
	{
		for(Face f:Face.values())
		{
			for(Suit s:Suit.values())
			{
				System.out.print("The "+f+" of "+s+"\n");
			}
			
		}
		
	}


My setCard method used in my default constructor Deck() and my showDeck method I was somewhat grabbing inspiration for my default Deck() constructor.

Oh and this is my first time posting here! Thanks for any help I may receive!

Viewing all articles
Browse latest Browse all 51036

Trending Articles