所以,我必須使用函數/方法和數組創建一個撲克手形程序。Java:撲克手
下面是一個示例輸出,我需要有:
Enter five numeric cards, no face cards. Use 2 - 9.Card 1: 8 Card 2: 7 Card 3: 8 Card 4: 2 Card 5: 7 Two Pair! Enter five numeric cards, no face cards. Use 2 - 9. Card 1: 4 Card 2: 5 Card 3: 6 Card 4: 8 Card 5: 7 Straight! Enter five numeric cards, no face cards. Use 2 - 9. Card 1: 9 Card 2: 2 Card 3: 3 Card 4: 4 Card 5: 5 High Card!
這裏是我的代碼(我在與邏輯問題,確定一個得到一種對,3等)。他們有方法/功能。所以,如果我能想出如何做1〜2其中,它應該是希望從那裏微風:
import java.util.Scanner;
public class Assignment4
{
public static void main(String args[])
{
final int LEN = 5;
int[] hand = new int[LEN];
Scanner input = new Scanner(System.in);
//input the hand
System.out.println("Enter five numeric cards, no face cards. Use 2-9.");
for (int index = 0; index < hand.length; index++) {
System.out.print("Card " + (index + 1) + ": ");
hand[index] = input.nextInt();
}
//sort the collection
bubbleSortCards(hand);
//determine players hand type
//flow of evaluation -> checking complex hands first
if (containsFullHouse(hand)) {
System.out.println("Full House!");
} else if (containsStraight(hand)) {
System.out.println("Straight!");
} else if (containsFourOfaKind(hand)) {
System.out.println("Four of a Kind!");
} else if (containsThreeOfaKind(hand)) {
System.out.println("Three of a Kind!");
} else if (containsTwoPair(hand)) {
System.out.println("Two Pair!");
} else if (containsPair(hand)) {
System.out.println("Pair!");
} else
System.out.println("High Card!");
}
這是從分配的說明書推薦的方法:
public class PokerHand
{
public static void main(String args[])
{
int hand[] = {5, 2, 2, 3, 8};
if (containsAPair(hand)) {
System.out.println("Pair!");
} else {
System.out.println("Not a pair!");
}
}
public static boolean containsAPair(int hand[]) {
// Your code here... don’t return true every time...
return true;
}
}
如果需要更多信息,我將非常樂意提供。謝謝!
什麼是你的問題 – Jay 2014-09-10 20:55:46
作業4 :-) – rlegendi 2014-09-10 20:57:05
所以在這裏說'//你的代碼在這裏......不要每次都返回真實......',你有什麼嘗試? – jdphenix 2014-09-10 20:59:34