943,822 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 928
  • Java RSS
Mar 14th, 2009
0

Java Project Help...

Expand Post »
Hi everyone, id firstly like to start off by saying i am new here and if i make any mistakes in anyway i am sorry in advance...

I was wondering if anyone could "HELP" me complete a project that i am doing, i basically have to create the card game (21 - Blackjack/Pontoon)

And need abit of help as in where to start...What ill need in terms of classes, methods in classes etc... Im not asking anyone to do it for me i no that for those who start saying im asking people to do it for me (which i dont) i just need some advice on where to make a start and how to make a start. If anyone is interested in helping me could you please send me a pm and i can send you the rules of the game that i need to implement into the code...

Thank you all for taking your time to read this thread.
Have a nice day

The 1.

p.s. hope to hear from people soon, remember if you do wish to help me i will forward the poject rules to you (dont wanna waste other peoples time by posting it all here) Thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
The 1 is offline Offline
12 posts
since Mar 2009
Mar 14th, 2009
0

Re: Java Project Help...

I was told to make UML diagrams firstly, as that would help, but im stuck on that to like what types of method would each class need. The classes i think this project would need are:

Card
Deck
Game
Hand

(Thats a guess, but im not 100% sure, its just about what kind of methods each one would have... :s )
Reputation Points: 10
Solved Threads: 0
Newbie Poster
The 1 is offline Offline
12 posts
since Mar 2009
Mar 14th, 2009
0

Re: Java Project Help...

Sorry, don't have the time to do much on this, but start with a Card class (52 instances!) and a Player class (that holds a list of the Cards that the player holds, the player's current cash and bet, and has the logic for stick/twist etc). Maybe a Dealer class that has the logic to "deal" Cards to Players and perform it's own versions of the stick/twist logic, and compute payouts (subclass Player to avoid duplication).
Featured Poster
Reputation Points: 1924
Solved Threads: 951
Posting Expert
JamesCherrill is online now Online
5,777 posts
since Apr 2008
Mar 14th, 2009
0

Re: Java Project Help...

Normally the idea on this forum is to not do things via PM since the goal is to make everything public, so you'll probably get a better response if you post the rules of the game on the thread.

I imagine you'll need a function to shuffle cards though, probably a function in the Deck class. I have a couple of code snippets in the C++ section dealing with that:

http://www.daniweb.com/code/snippet1019.html
http://www.daniweb.com/code/snippet1034.html

The first one is probably useless for Java since it involves pointers, but the second may come in handy and could be transformed into Java fairly easily.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,374 posts
since Jan 2008
Mar 14th, 2009
0

Re: Java Project Help...

When I programmed Blackjack I used an ArrayList to hold all my cards. To shuffle I simply had a for loop run about 1000 times, randomly picking a number 0-51, removing the object at that spot while at the same time adding it to the end. Just another idea for a shuffle 'algorithm'. I wouldn't use this with a lot of elements but with 52 it works well.

java Syntax (Toggle Plain Text)
  1. public void shuffle(){
  2. for(int i=0;i<1000;i++){
  3. int rand = (int)(Math.random()*50)+1;
  4. deck.add(deck.remove(rand));
  5. }
  6. }

It took about 0.003169118 seconds to shuffle.
Last edited by jasimp; Mar 14th, 2009 at 3:32 pm.
Featured Poster
Reputation Points: 533
Solved Threads: 53
Senior Poster
jasimp is offline Offline
3,593 posts
since Aug 2007
Mar 14th, 2009
0

Re: Java Project Help...

Iv uploaded the code so far on rapidshare if you could just download it and check it out that would be greatly appreciated, it dont seem to compile...

http://rapidshare.com/files/209260005/pontoon.rar

Thanks in advance
1
Reputation Points: 10
Solved Threads: 0
Newbie Poster
The 1 is offline Offline
12 posts
since Mar 2009
Mar 14th, 2009
1

Re: Java Project Help...

Click to Expand / Collapse  Quote originally posted by The 1 ...
Iv uploaded the code so far on rapidshare if you could just download it and check it out that would be greatly appreciated, it dont seem to compile...
You need to post the section of code that is giving you trouble here, not the whole thing, only where you are getting an error (don't forget to tell us what error/exception you are getting.) A great skill to have is the ability to go through your code and figure out why "it don't seem to compile", if you ask for help every time the answer doesn't dance around naked in front of your face, you'll never develop that skill.
Last edited by jasimp; Mar 14th, 2009 at 6:13 pm.
Featured Poster
Reputation Points: 533
Solved Threads: 53
Senior Poster
jasimp is offline Offline
3,593 posts
since Aug 2007
Mar 14th, 2009
0

Re: Java Project Help...

This is the line im getting my error in:

Java Syntax (Toggle Plain Text)
  1. private ArrayList<Card> card = new ArrayList<card>();

and the error says "cannot find symbol - class card"

Thanks...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
The 1 is offline Offline
12 posts
since Mar 2009
Mar 14th, 2009
0

Re: Java Project Help...

Java Syntax (Toggle Plain Text)
  1. import java.util.*;
  2. import java.util.Collection.*;
  3.  
  4. class DeckOfCards
  5. {
  6. private ArrayList<Card> card = new ArrayList<card>();
  7.  
  8. public DeckOfCards()
  9. {
  10. for(int i=0; i < 52; i++)
  11. {
  12. if(i < 13)
  13. card.add(new Card(i%13+1,'S'));
  14. else
  15. if(i < 26)
  16. card.add(new Card(i%13+1, 'H'));
  17. else
  18. if(i < 39)
  19. card.add(new Card(i%13+1, 'D'));
  20. else
  21. card.add(new Card(i%13+1, 'C'));
  22. }
  23. }
  24.  
  25. public void shuffle()
  26. {
  27. Collection.shuffle(card);
  28. }
  29.  
  30. public Card pickNextCard()
  31. {
  32. return card.remove(0);
  33. }
  34. }

Java Syntax (Toggle Plain Text)
  1. class Card
  2. {
  3. private int rank;
  4. private char suit;
  5.  
  6. public int getRank()
  7. {
  8. return(rank);
  9. }
  10.  
  11. public int getSuit()
  12. {
  13. return(suit);
  14. }
  15.  
  16. public Card(int r, char s)
  17. {
  18. rank = r;
  19. suit = s;
  20. }
  21.  
  22. public boolean equals(Card otherCard)
  23. {
  24. if((rank == otherCard.rank) && (suit == otherCard.suit))
  25. return(true);
  26. else
  27. return(false);
  28. }
  29. }

Since these are in separate files, try putting the word "public" at the top next to the name of the class. I would think that you would get some other errors besides just the one you listed, but stick the word "public" in front of the word "class" in your java files and see if the errors go away.

[Edit]
Note: Java is case sensitive:

    private ArrayList<Card> card = new ArrayList<card>();

Red above should be capitalized.
[/Edit]
Last edited by VernonDozier; Mar 14th, 2009 at 6:59 pm.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,374 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: How to find local systems free space?
Next Thread in Java Forum Timeline: what's wrong?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC