Project is due before midnight eastern time (3 more hours). I have been working on this all day, we have not learned arrays or anything and just started 'for' loops. I don't really know how to implement that system yet. However, he wants us to check all the possible handwritten math ways of doing this. I have tried but I cannot return my numbers beside the card. I will post the question below, my program only prints the type and I still have more cases to add as well.. Meanwhile I am going to try and teach myself arrays, but he will probably think i am cheating and fail the grade for that..Appreciate your guys opinions and help. I was trying to set up a new function or method and have it print a string for the numbers but I realized I can't do that either...Lost..
QUESTION: Write a Java program that reads 5 integers, each of which is in the range of 1 and 13 representing a simplified poker card with no suit. Your program should then print the ranking of the hand with card number(s) beside the ranking. The rankings to determine are Four of a Kind(4 of the 5 cards of the same rank), Full House(3 of the 5 cards of the same rank, and 2 cards of another rank), Straight(5 cards of sequential rank), Three of a Kind(only 3 cards of the same rank), Two Pair(2 cards of the same rank, 2 cards of another rank, and no card of either rank), One Pair(only 2 of 5 cards are of the same rank), and High Card(no two cards of the same rank). Some sample runs are:
input: 2, 3, 2, 2, 2; output: Four of a Kind(2)
input: 2, 3, 2, 3, 2; output: Full House(2, 3)
input: 2, 3, 4, 5, 1; output: Straight(5)
input: 1, 13, 11, 10, 12; output: Straight(1)
input: 2, 3, 2, 2, 4; output: Three of a Kind(2)
input: 1, 9, 8, 9, 1; output: Two Pair(1, 9)
input: 2, 9, 8, 9, 2; output: Two Pair(9, 2)
input: 3, 9, 8, 9, 1; output: One Pair(9)
input: 2, 10, 7, 12, 5; output: High Card(12)
input: 2, 1, 7, 12, 5; output: High Card(1)
import java.util.Scanner; public class Hw6 { static int getCard(int c1, int c2, int c3, int c4, int c5){ if (c1 > c2) { int t = c1; c1 = c2; c2 = t; } if (c2 > c3) { int t = c2; c2 = c3; c3 = t; } if (c3 > c4) { int t = c3; c3 = c4; c4 = t; } if (c4 > c5) { int t = c4; c4 = c5; c5 = t; } if (c1 > c2) { int t = c1; c1 = c2; c2 = t; } if (c2 > c3) { int t = c2; c2 = c3; c3 = t; } if (c3 > c4) { int t = c3; c3 = c4; c4 = t; } if (c1 > c2) { int t = c1; c1 = c2; c2 = t; } if (c2 > c3) { int t = c2; c2 = c3; c3 = t; } if (c1 > c2) { int t = c1; c1 = c2; c2 = t; } System.out.println(c1+", "+c2+", "+c3+", "+c4+", "+c5); if (c1 == c2 && c2 == c3 && c3 == c4 || c2 == c3 && c3 == c4 && c4 == c5) return 1; //four of a kind else if (c1 == c2 && c2 == c3 && c4 == c5 || c1 == c2 && c3 == c4 && c4 == c5) return 2; //full house else if (c2-c1 == 1 && c3-c2 == 1 && c4-c3 == 1 && c5-c4 == 1 || c2-c1 == 1 && c3-c2 == 1 && c4-c3 == 1 && c5-c4 != 1) return 3; //straight else if (c1 == c2 && c2 == c3 && c4 != c5 || c1 != c2 && c3 == c4 && c4 == c5) return 4; //three of a kind else if (c2 == c3 && c4 == c5 || c1 == c2 && c4 == c4) return 5; //two pair else if (c1 == c2 || c2 == c3 || c3 == c4 || c4 == c5) return 6; //one pair else return 7; //high card } public static void main(String[] args) { Scanner in = new Scanner(System.in); String s1,s2,s3,s4,s5; int c1,c2,c3,c4,c5; int card; System.out.print("Enter 1st card number(1-13): "); c1 = in.nextInt(); System.out.print("Enter 2nd card number(1-13): "); c2 = in.nextInt(); System.out.print("Enter 3rd card number(1-13): "); c3 = in.nextInt(); System.out.print("Enter 4th card number(1-13): "); c4 = in.nextInt(); System.out.print("Enter 5th card number(1-13): "); c5 = in.nextInt(); card = getCard(c1,c2,c3,c4,c5); switch (card) case 1: System.out.println("Four of a kind"); break; case 2: System.out.println("Full House"); break; case 3: System.out.println("Straight"); break; case 4: System.out.println("Three of a Kind"); break; case 5: System.out.println("Two Pair"); break; case 6: System.out.println("One Pair"); break; case 7: System.out.println("High Card"); break; } } }
--- Update ---
Bump, any ideas are now being taken into consideration..Anything at all.