Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Urgent help needed (again)

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Location
    Kentucky
    Posts
    11
    My Mood
    Worried
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Urgent help needed (again)

    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.


  2. #2
    Member
    Join Date
    Aug 2013
    Posts
    95
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Default Re: Urgent help needed (again)

    My advice would be set aside a method for each case. For example do a method for checking if the cards are a straight, do another method checking if they are full house.. so on so forth. It will help keep your code much more organized and easier to debug later if needed.

  3. The Following User Says Thank You to camel-man For This Useful Post:

    goodtanner (October 9th, 2014)

  4. #3
    Junior Member
    Join Date
    Aug 2014
    Location
    Kentucky
    Posts
    11
    My Mood
    Worried
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Urgent help needed (again)

    Will do, but the main issue is returning the numbers along side the type of hand.

  5. #4
    Member
    Join Date
    Aug 2013
    Posts
    95
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Default Re: Urgent help needed (again)

    if you make it into a method than you can convert the two numbers into a string and return the String. Instead of returning two numbers

  6. #5
    Junior Member
    Join Date
    Aug 2014
    Location
    Kentucky
    Posts
    11
    My Mood
    Worried
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Urgent help needed (again)

    I will give that a quick go, thanks for the advice, but I didnt think I could even implement a way to return the numbers to a switch case anyways. A tutor at my school told me that it was impossible but then again who knows..I am really starting to wonder what I am being told..Lol. Appreciate it.

  7. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Urgent help needed (again)

    You waited too long to ask for help. Give yourself more time, ask for help when you need it.

Similar Threads

  1. Urgent Ideas Needed
    By goodtanner in forum Object Oriented Programming
    Replies: 7
    Last Post: September 27th, 2014, 03:15 AM
  2. help needed (URGENT)
    By sour_bee in forum Java Theory & Questions
    Replies: 2
    Last Post: December 16th, 2013, 01:55 PM
  3. URGENT HELP NEEDED WITH ALGORITHM PLEASE! PLEASE! .... THANKS
    By Honours in forum Java Theory & Questions
    Replies: 6
    Last Post: March 13th, 2011, 08:40 PM
  4. urgent help needed
    By nono in forum Member Introductions
    Replies: 2
    Last Post: March 10th, 2011, 11:18 AM
  5. Urgent help needed
    By mohit1007 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: June 23rd, 2010, 09:34 PM