Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Urgent java help
#1
Hi I need java help again
I have this card class:


class Card {

   private final char suit;
   private final int face;

   /*
   initialises with suit ('S'=spade, 'H'=heart, 'D'=diamonds, 'C'=clubs)
   and face (1=ace, 2, ... 10, 11=knight, 12=queen and 13=king).
   */

   public Card(char suit, int face) {
       this.suit = suit;
       this.face = face;
   }

   @Override
   public String toString() {
       return String.format("%s%s", suit, face);
   }

   public char getSuit() {
       return suit;
   }

   public int getFace() {
       return face;
   }
}



I'm supposed to make a Deck class that creates a deck of cards. This is my attempt, and I'm not sure if I've done it right. I've tried creating the deck as well as printing the deck, but it doesn't seem to work.

class Deck {
   public static void main(String[] args) {

       Card[] cards;

       public Deck(int n){
           this.cards = new Card[n];
       }

       public Deck() {
           this.cards = new Card[52];
           int index = 0;
           for (int suit = 0; suit <= 3; suit++) {
               for (int rank = 1; rank <= 13; rank++) {
                   this.cards[index] = new Card(rank, suit);
                   index++;
               }
           }
       }

       Deck deck = new Deck();

       public void print () {
           for (int i = 0; i < this.cards.length; i++) {
               System.out.println(this.cards[i]);
           }
       }
   }
}



I get an illegal start of expression error at line 6 ( public Deck (int n) { )
Reply


Messages In This Thread
Urgent java help - bro - 2020-01-22 15:24:36
RE: Urgent java help - bro - 2020-01-22 16:56:29
RE: Urgent java help - Verdusk - 2020-01-22 20:00:46
RE: Urgent java help - bro - 2020-01-23 09:13:54
RE: Urgent java help - bro - 2020-01-23 09:44:31
RE: Urgent java help - Verdusk - 2020-01-23 11:02:30



Users browsing this thread: 1 Guest(s)