Ok...what I am trying to do is create a deck of cards which is done in my Deck class and each card in the deck is created in the card class. I would like to create a new method in my card class to get the face value and another method to get the suit of each card. I am supposed to do this in the card class...how can I do this?
Here is my card class:
Here is my deck class:Code:package deckofcards; public class Card { String suit; int faceValue; /** Constructor statement */ /** Creates a new instance of Card */ public Card(String suit, int x) { this.suit = suit; this.faceValue = x; } public void getMyFaceValue(int cardNum) { } public void getMySuit() { } }
Also, the showCards() method in the deck class doesn't display properly. Can anyone tell me why? It looks like it outputs the memory address of each card object.Code:package deckofcards; public class Deck { Card[] my_cards = new Card[52]; static String[] suitType = {"Heart", "Club", "Diamond", "Spade"}; public Deck() { for (int i = 0; i < 52; i++) { int suit = i / 13; int value = i % 13 + 1; my_cards[i] = new Card(suitType[suit], value); } } public Card getCard(int index) { Card c = my_cards[index]; return c; } public void showDeck() { /** Displays all 52 cards */ for(int j = 0; j < 52; j++) { System.out.println(my_cards[j].faceValue + " of " + my_cards[j].suit); } } }
Yes this is a homework assignment in my class...but I dont know java and I need a little help. Thanks!





Reply With Quote