简体   繁体   中英

Deck of cards error java

public class Cards {
private Cards deck[];
private int currentcard;
private static final int Number_of_Cards=52;
private static final Random randomNumbers= new Random();
public DeckofCards()
{
    String[] faces = {"Ace", "Deuce", "Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};
    String[] suits ={"Hearts","Diamonds","Clubs","Spades"};
    deck = new Cards[Number_of_Cards];
    currentcard=0;
    for (int c=0; c<deck.length; c++)
        deck[c]= new Cards(faces[c%13],suits[c/13]); //error here
   }
  }

This is the code i have so far in order to fill my Deck of cards, this is from a java learning book though it seems i have an error in that last line:
Constructor Cards in class Cards cannot be applied to given types: required:no arguments found:String,String reason:actual and formal argument lists differ in length
Thanks for help!

You're creating a object new Cards(faces[c%13],suits[c/13]); with parameters, but your Cards class doesn't have a constructor which takes arguments. Create a constructor which takes two String arguments.

您尚未指定任何构造函数(因此显然不存在具有两个String参数的构造函数),因此Java仅假定默认构造函数

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM