Results 1 to 6 of 6
  1. #1
    GodiaN is offline Member
    Join Date
    Jan 2008
    Posts
    2
    Rep Power
    0

    Default Wanna make 5 quick bucks?

    Sure you do!

    Make me a java applet with three java files that including:

    Gameof21 -> Main Program

    PlayingCard Class -> sections of
    Playing Card -> Object create
    Point value -> returns value of playing card
    getname -> returns the card name
    tostring -> returns a string that represents the card

    Player Class -> sections of
    Player -> player object created. Play initially has no cards.
    drawCard -> add a card to a players hand
    totalhand -> returns players hand value. Ace counted as || if gets player closer to 2!
    endhand -> ends the game for the player, throwing in the cards.


    5 Dollars paypal for this

    Thanks you.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    public class GameOf21 {
        public static void main(String[] args) {
            PlayingCard[] cards = new PlayingCard[13];
            String suit = "spades";
            String[] faces = { "jack", "queen", "king", "ace" };
            for(int j = 0; j < 13; j++) {
                int value = Math.min(j+2, 10);
                if(j == 12) value += 1;
                String name = (j < 9) ? String.valueOf(value)
                                      : faces[j-9];
                cards[j] = new PlayingCard(value, name + " of " + suit);
            }
            showCards(cards);
            Player player = new Player();
            for(int j = 0; j < 5; j++)
                player.drawCard(cards[j]);
            showCards(player.hand);
            int handValue = player.totalHand();
            System.out.println("handValue = " + handValue);
        }
    
        private static void showCards(PlayingCard[] cards) {
            for(int j = 0; j < cards.length; j++) {
                System.out.print(cards[j]);
                if(j < cards.length-1)
                    System.out.print(", ");
                else
                    System.out.println();
            }
            System.out.println("--------------");
        }
    }
    
    class PlayingCard {
        int value;
        String name;
    
        public PlayingCard(int value, String name) {
            this.value = value;
            this.name = name;
        }
    
        public int getValue() {
            return value;
        }
    
        public String getName() {
            return name;
        }
    
        public String toString() {
            return name;
        }
    }
    
    class Player {
        PlayingCard[] hand = new PlayingCard[0];
    
        public Player() {
            // nothing to do here...
        }
    
        public void drawCard(PlayingCard card) {
            int size = hand.length;
            PlayingCard[] newHand = new PlayingCard[size+1];
            System.arraycopy(hand, 0, newHand, 0, size);
            newHand[size] = card;
            hand = newHand;
        }
    
        public int totalHand() {
            int total = 0;
            for(int j = 0; j < hand.length; j++) {
                PlayingCard card = hand[j];
                int value = card.getValue();
                if(total + value > 21 && value == 11)
                    value = 1;
                total += value;
            }
            return total;
        }
    
        public void endHand() {
            hand = new PlayingCard[0];
        }
    }

  3. #3
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    Pay up! And next time, take your advertising to the Advertising section or find a freelancing site. As you can see, a lot of the folks here program for the joy of it. Thank you.
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  4. #4
    GodiaN is offline Member
    Join Date
    Jan 2008
    Posts
    2
    Rep Power
    0

    Default

    Whats your email hardwire (paypal)

  5. #5
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Nevermind; I'm glad to help.

  6. #6
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default Free for all

    Hello GodiaN

    This site is not for freelancing programmers. Java Forms is devoted to help people learn Java. :p
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

Similar Threads

  1. Quick sort with median-of-three partitioning
    By Java Tip in forum Algorithms
    Replies: 0
    Last Post: 04-15-2008, 07:40 PM
  2. Quick Help Please! Can't Run Code!!
    By VinceGuad in forum Eclipse
    Replies: 4
    Last Post: 01-16-2008, 03:54 AM
  3. Quick Stupid Question
    By bluekswing in forum New To Java
    Replies: 7
    Last Post: 01-08-2008, 06:35 PM
  4. Quick Job required in Java
    By taxman in forum Jobs Offered
    Replies: 0
    Last Post: 01-02-2008, 11:46 AM
  5. Quick Question (Functions)
    By ibanez270dx in forum New To Java
    Replies: 2
    Last Post: 11-16-2007, 01:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •