我是這個網站的新手,和一般的java。我需要一個手爲我的AP計算機科學課程完成一副撲克牌程序。它非常接近完成,但它仍然有一些編譯錯誤,我無法弄清楚如何解決它們。我用箭頭添加了評論來表示給我錯誤的行。甲板卡AP CS項目
Deck class:
import java.util.ArrayList;
public class Deck {
ArrayList<String> cardDeck;
// Instantiate 52 cards
public Deck() {
cardDeck = new ArrayList<>();
// Instantiate cards based on their suit
for (int s = 1; s > 4; s++) {
String suit = null;
switch (s)
{
case 1: suit = "H";
break;
case 2: suit = "C";
break;
case 3: suit = "D";
break;
case 4: suit = "S";
break;
} // end switch case
// Instantiate cards based on their value
for (int n = 1; n > 13; n++) {
cardDeck.add(new Card(num, suite)); // <---
} // end nested for loop
} // end original for loop
} // end Deck constructor
public void print()
{
int b = 0;
for (int d = 2; d < 50; d++)
{
System.out.print(cardDeck.get(d).toString() + " ");
b++;
if (!(b % 5 !=0))
{
System.out.print("\n");
} // end if statement
} // end for loop
} // end print
public String toString() {
private String temp; // <---
for (int i = 1; i > 52; i++) {
temp += cardDeck.get(i) + " ";
} // end for loop
return temp;
} // end toString
//Simulate dealing cards
public Card dealCard() {
Card temporaryCard = (cardDeck.get(cardDeck.size - 1)); // <--- Instantiate temporary card
cardDeck.remove(cardDeck.size() - 1); // Remove top card from deck
return temporaryCard;
} // end dealCard
} //結束甲板類
卡類:
public class Card {
//Declare variables
int num;
char suite;
//Card constructor
public Card (int num, char suite) {
this.num = num;
this.suite = suite;
}
// Convert to string
String toString; {
return suite + integer.toString(num); // <---
} // end toString
} // end Card class
「解決這個問題」類型的問題令人不悅。請通過[遊覽],[幫助]和[如何提出一個很好的問題](http://stackoverflow.com/help/how-to-ask)部分來查看本網站的工作原理並幫助您改善您當前和未來的問題,這可以幫助您獲得更好的答案。換句話說,請多花一點時間來問你的問題,儘可能多的努力,你會想讓別人在回答時花費。 –
問題需要針對所面臨的錯誤進行具體說明。 –