Homework Help! Urgent!

Discussion in 'Java' started by xscarsofdesirex, Feb 27, 2005.

  1. Probably a very simple program, but I am completely stumped.
    Any help in coding (even hints) for this would be GREATLY
    appreciated.
    If you would like to contact me directly, my AIM is XscarsofdesireX.


    Write a class called Card where each object represents a card. The
    class should have three instance variables.
    int myNum (stores a value 1 to 52)
    String mySuit (suit of the card- to be determined by myNum)
    String myValue (value of the card -1,....10,Jack, Queen, King, Ace)
    (use integer division for mySuit and % for myValue)

    The class should have a setValue() and setSuit(). They should be
    called in the constructor.

    Then write a class called DeckOfCards that holds 52 objects of type
    cards. Write methods that will assign each card a different number 1
    to 52, will shuffle the deck, will deal a card, and tell how many
    cards are left.

    Create a driver that will shuffle the deck, then pring out as many
    cards as the user wants dealt from the top of the deck.


    Posted Via Usenet.com Premium Usenet Newsgroup Services
    ----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
    ----------------------------------------------------------
    http://www.usenet.com
     
    xscarsofdesirex, Feb 27, 2005
    #1
    1. Advertising

  2. xscarsofdesirex

    Dotty Guest

    "xscarsofdesirex" <-spam.invalid> wrote in
    message news:4222276d_2@127.0.0.1...
    > Probably a very simple program, but I am completely stumped.
    > Any help in coding (even hints) for this would be GREATLY
    > appreciated.
    > If you would like to contact me directly, my AIM is XscarsofdesireX.
    >
    >
    > Write a class called Card where each object represents a card. The
    > class should have three instance variables.
    > int myNum (stores a value 1 to 52)
    > String mySuit (suit of the card- to be determined by myNum)
    > String myValue (value of the card -1,....10,Jack, Queen, King, Ace)
    > (use integer division for mySuit and % for myValue)
    >
    > The class should have a setValue() and setSuit(). They should be
    > called in the constructor.
    >
    > Then write a class called DeckOfCards that holds 52 objects of type
    > cards. Write methods that will assign each card a different number 1
    > to 52, will shuffle the deck, will deal a card, and tell how many
    > cards are left.
    >
    > Create a driver that will shuffle the deck, then pring out as many
    > cards as the user wants dealt from the top of the deck.
    >

    Hi:
    What I do is search with google or whatever to find a demo
    or example someplace that is close to what I want to do and then
    modify that. If you find some code that you actually use, you have
    to tell the teacher or risk getting an 'f'.
    Good luck.
     
    Dotty, Feb 27, 2005
    #2
    1. Advertising

  3. xscarsofdesirex

    Rhino Guest

    "xscarsofdesirex" <-spam.invalid> wrote in
    message news:4222276d_2@127.0.0.1...
    > Probably a very simple program, but I am completely stumped.
    > Any help in coding (even hints) for this would be GREATLY
    > appreciated.
    > If you would like to contact me directly, my AIM is XscarsofdesireX.
    >
    >
    > Write a class called Card where each object represents a card. The
    > class should have three instance variables.
    > int myNum (stores a value 1 to 52)
    > String mySuit (suit of the card- to be determined by myNum)
    > String myValue (value of the card -1,....10,Jack, Queen, King, Ace)
    > (use integer division for mySuit and % for myValue)
    >
    > The class should have a setValue() and setSuit(). They should be
    > called in the constructor.
    >
    > Then write a class called DeckOfCards that holds 52 objects of type
    > cards. Write methods that will assign each card a different number 1
    > to 52, will shuffle the deck, will deal a card, and tell how many
    > cards are left.
    >
    > Create a driver that will shuffle the deck, then pring out as many
    > cards as the user wants dealt from the top of the deck.
    >

    Hint: Have a look at the Collections trail in the Java Tutorial, especially
    the List interfaces. The URL for the Collections trail is
    http://java.sun.com/docs/books/tutorial/collections/index.html; I'll let you
    do the digging to find the topic on the List interface.

    Rhino
     
    Rhino, Feb 27, 2005
    #3
  4. xscarsofdesirex

    Malte Guest

    xscarsofdesirex wrote:
    > Probably a very simple program, but I am completely stumped.
    > Any help in coding (even hints) for this would be GREATLY
    > appreciated.


    If you had at least indicated that you knew the basics of Java, but you
    couldn't even be bothered to do that. Surely, you must have a textbook
    for the course.

    Look for hints related to class definition and creation then look at
    fields and methods.
    After that, look at arrays. Forget about fancy Collection classes stuff.
    You seem to be in need of the basic understanding.
    If you still don't know what I am talking about, read your textbook up
    until and including the text that will enable you to finish the assignment.
     
    Malte, Feb 28, 2005
    #4
  5. xscarsofdesirex

    Malte Guest

    Malte wrote:
    > xscarsofdesirex wrote:
    >
    >> Probably a very simple program, but I am completely stumped.
    >> Any help in coding (even hints) for this would be GREATLY
    >> appreciated.

    >
    >
    > If you had at least indicated that you knew the basics of Java, but you
    > couldn't even be bothered to do that. Surely, you must have a textbook
    > for the course.
    >
    > Look for hints related to class definition and creation then look at
    > fields and methods.
    > After that, look at arrays. Forget about fancy Collection classes stuff.
    > You seem to be in need of the basic understanding.
    > If you still don't know what I am talking about, read your textbook up
    > until and including the text that will enable you to finish the assignment.


    Just in case you thought I was a bit harsh, I decided to spoon feed.

    Enter this into Google (www.google.com):

    java deck of cards example

    Among the results is the url:

    http://www.javacoffeebreak.com/books/extracts/javanotesv3/source/index.html

    Which, when using ctl+f in Firefox or the equivalent in MSIE or Opera,
    eventually will lead to these:

    http://www.javacoffeebreak.com/books/extracts/javanotesv3/source/Card.java
    and
    http://www.javacoffeebreak.com/books/extracts/javanotesv3/source/Deck.java

    The entire excercise took me 2-3 minutes.

    Obviously, none of the above will help you actually understand what
    you're doing. For that you will have to work.
     
    Malte, Feb 28, 2005
    #5
  6. xscarsofdesirex

    Alun Harford Guest

    "Malte" <forgetme@spam_here.nowhere.com> wrote in message
    news:cvts13$2gui$...

    > http://www.javacoffeebreak.com/books/extracts/javanotesv3/source/Card.java


    Actually, that's a really bad way to make a Card class.
    In any program where you want one card, they're probably an object you want
    lots of, and you'll be using all the time.

    What you actually want to do is have a private constructor to create a
    Card[][] so you can get a Card with Card.ALLCARDS[Card.HEART][Card.THREE]

    If you do it the other way you can easily spent half your CPU time
    constructing Card objects. This way also lets you use Object.equals(Object
    obj) to test if two cards are the same, and they hash to the same value etc
    etc etc. Nicer, less work and quicker. (If only I'd thought of that the
    first time!)

    Alun Harford
     
    Alun Harford, Feb 28, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    0
    Views:
    684
    Guest
    Feb 25, 2004
  2. Rhino

    need help with homework

    Rhino, Nov 16, 2003, in forum: Java
    Replies:
    1
    Views:
    307
    Roedy Green
    Nov 16, 2003
  3. Andrew Thompson
    Replies:
    33
    Views:
    899
    Alex Hunsley
    Oct 30, 2004
  4. Replies:
    2
    Views:
    413
    Roedy Green
    Oct 10, 2005
  5. Allens Mail

    Need Help On Homework

    Allens Mail, Jul 13, 2003, in forum: C++
    Replies:
    1
    Views:
    377
    Aggro
    Jul 14, 2003
Loading...

Share This Page