473,574 Members | 2,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Help on Java Calculation Card Game!!!!!!

5 New Member
Hello, I am new to learning java, and i am trying to build the class for a calculation card game, unfortunately i can't get the public Card top() and Card takeTop() method in the Stock class. Can someone helps me.
Thanks!!
-----------------------------------------------------------------------
The code for the Stock class:
-----------------------------------------------------------------------
public class Stock
{
private Deck deck = new Deck(52);
private int X;
private int Y;

public Stock(Deck deck)
{
this.deck = deck;
}


/**
* Draw the stock as a facedown card and then the top card of
* the stock slightly to the right of and below the face-up card.
*/
public void draw(java.awt.G raphics g)
{

}

/**
* The number of cards in the stock(including the top card).
* @return the number of cards.
*/
public int numCardsRemaini ng()
{
return deck.numCardsRe maining();
}

/**
* Take the top card from the stock.
* @return the card that was on top of the stock or null if the stock was empty.
* A call to this method reduces the number of cards remaining in the stock by one.
*/
public Card takeTop()
{
return ?????????????
}

/**
* The top card of the stock.
* @return the top card of the stock, or null if the stock is empty.
* Acall to this method does not remove the card from the top but
* just returns a reference to it.
*/

public Card top()
{
if(deck.numCard sRemaining()==0 )
{
return null;
}
else
{
return ?????????
}

}

}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
in order to solve the problems you need to know Deck class too, but we can't modify this class as assignment requires.

-----------------------------------------------------------------------
The code for Deck class:
-----------------------------------------------------------------------

import java.util.*;
import java.awt.*;

public class Deck
{
private java.util.List< Card> cards; // The list of cards
private static java.util.Rando m generator = null;

/**
* Constructor for a shuffled deck of cards.
* @param seed the seed for the random number generator used to
* shuffle the deck. A different unique shuffle is obtained for
* each possible value of seed.
*/
public Deck(long seed)
{
// Create a deck of cards in sorted order of suit then pip count.

cards = new ArrayList<Card> ();
for (int suit = Card.SPADES; suit <= Card.CLUBS; suit++) {
for (int pips = 1; pips <= Card.CARDS_IN_S UIT; pips++) {
cards.add(new Card(suit, pips));
}
}

// Now shuffle the deck, using a random number generator based
// on the seed value given as a parameter.

java.util.Rando m generator = new java.util.Rando m(seed);
java.util.Colle ctions.shuffle( cards, generator);
}

public int numCardsRemaini ng()
{
return cards.size();
}

/**
* Get the next card from the deck, reducing the number of cards
* remaining in the deck by one.
* @return the "top" card in the deck
*/
public Card nextCard()
{
return cards.remove(0) ;
}

/**
* Add the given card to the start (front) of the current deck.
* @param card the card to be placed at the start of the deck
*/
public void addAtStart(Card card)
{
cards.add(0, card);
}

/**
* Add the given card to the end (back) of the current deck.
* @param card the card to be placed on the end of the deck
*/
public void addAtEnd(Card card)
{
cards.add(card) ;
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
so basically my problems are how to get public Card top() and public Card takeTop() methods working in the Stock class without modify the Deck class.
Thanks!!!!!!!!! :)
May 16 '06 #1
0 3000

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2615
by: Sam | last post by:
Hey all, I want to create a computerised version of this game, though I'm not really sure how to go about it. For those who don't know how the game works, here's my attempt at a brief description: It is very similar to the card game Uno, though played with a standard deck of cards. An initial card is played off the top of the deck, and...
1
2679
by: Gary Camblin | last post by:
Has anyone got a script to run a higher or lower card game on a web page. Like the game show play you cards right.
1
2673
by: On Holidays | last post by:
Such thing as a PC java mobile phone game emulator for pc ??? I like games of any kind :) Thanks. /ps Would Be most interested o=in one that playsall games, From all
0
3685
by: Paul | last post by:
Greetings: I have been trying to find source code for a Baccarat card game (C++ or Basic, but preferably the former). My reason for this is wanting to experiment with possible Baccarat card counting methodologies, which is a controversial subject but I'd like to try out some ideas. However, I know very little C++ and am having real...
1
1547
by: Geoff | last post by:
Hi all, I've been making a card game in VB and am trying to get it work over a network. I think I've got all the card game pretty much planned out ready to make it, but need to find a way to get 2 computers to talk to each other over a network. I can't save files to anywhere both computers can access on the network though. I was thinking this...
6
1867
by: JNeko | last post by:
Hello all, awesome site! I guess I am technically not a beginner in JAVA, but from my code you would not realize it! I don’t expect anyone to help me with this, but I figure I might as well as try and ask. Any help is really appreciated; this should be a piece of cake…driving me crazy. I am writing a simple program (from a book for fun) that...
1
4571
by: Olmar | last post by:
Hi, I am trying to write a version of the Hears card game. I can't figue out what is the best way to detect clicks on the cards. Using the cards.dll interface as described in tutorials like http://www.publicjoe.f9.co.uk/csharp/card00.html . Can anyone give me suggestions how to detect which card is clicked and how to redraw it at the...
3
2297
by: Fiona1200 | last post by:
Please help me..i have to write a code in java for a card game as follows. there are 4 players each with 4 decks of cards. each deck has four zeros - four seven as follows (0000,1111,2222,3333,4444,5555,6666,7777). each pack is then shuffled player 1 deals player 2 four of his cards, player 2 deals player 3, 4 of his cards and so on. when each...
0
2766
by: hini | last post by:
Hi all, I am considering creating a multiplayer card game to play with my friends over internet, and I want to do it in java, I am not pro in java so I read a little about sockets, serialization, RMI, servlets, EJB etc.. but I am still not sure what are the best technologies or architecture to use for communication between players and server....
0
7832
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8093
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8262
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8129
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5331
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3768
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3785
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2262
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.