卡片组错误java

时间:2014-04-05 14:49:44

标签: 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
   }
  }

这是我到目前为止填写我的Deck of cards的代码,这是来自一本java学习书,虽然看起来我在最后一行有一个错误:
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
感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

您正在创建带参数的对象new Cards(faces[c%13],suits[c/13]);,但您的Cards类没有带参数的构造函数。创建一个带有两个String参数的构造函数。

答案 1 :(得分:0)

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