Java Project Help...

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2009
Posts: 4
Reputation: The 1 is an unknown quantity at this point 
Solved Threads: 0
The 1 The 1 is offline Offline
Newbie Poster

Java Project Help...

 
0
  #1
Mar 14th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 4
Reputation: The 1 is an unknown quantity at this point 
Solved Threads: 0
The 1 The 1 is offline Offline
Newbie Poster

Re: Java Project Help...

 
0
  #2
Mar 14th, 2009
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 )
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 977
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 145
JamesCherrill JamesCherrill is offline Offline
Posting Shark

Re: Java Project Help...

 
0
  #3
Mar 14th, 2009
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).
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,828
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Java Project Help...

 
0
  #4
Mar 14th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3,584
Reputation: jasimp has a spectacular aura about jasimp has a spectacular aura about jasimp has a spectacular aura about 
Solved Threads: 52
Featured Poster
jasimp's Avatar
jasimp jasimp is offline Offline
Senior Poster

Re: Java Project Help...

 
0
  #5
Mar 14th, 2009
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.

  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.
"Argyou not with the hand you are dealt in cards or life." ---- Wizard and Glass
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 4
Reputation: The 1 is an unknown quantity at this point 
Solved Threads: 0
The 1 The 1 is offline Offline
Newbie Poster

Re: Java Project Help...

 
0
  #6
Mar 14th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3,584
Reputation: jasimp has a spectacular aura about jasimp has a spectacular aura about jasimp has a spectacular aura about 
Solved Threads: 52
Featured Poster
jasimp's Avatar
jasimp jasimp is offline Offline
Senior Poster

Re: Java Project Help...

 
1
  #7
Mar 14th, 2009
Originally Posted by The 1 View Post
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.
"Argyou not with the hand you are dealt in cards or life." ---- Wizard and Glass
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 4
Reputation: The 1 is an unknown quantity at this point 
Solved Threads: 0
The 1 The 1 is offline Offline
Newbie Poster

Re: Java Project Help...

 
0
  #8
Mar 14th, 2009
This is the line im getting my error in:

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

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

Thanks...
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,828
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Java Project Help...

 
0
  #9
Mar 14th, 2009
  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. }

  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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC