Homework Help! Urgent!

X

xscarsofdesirex

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.
 
D

Dotty

xscarsofdesirex said:
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.
 
R

Rhino

xscarsofdesirex said:
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
 
M

Malte

xscarsofdesirex said:
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.
 
M

Malte

Malte said:
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.
 
A

Alun Harford


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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top