CARD JAVA

New to java

Page 1 of 1

8 Replies - 3744 Views - Last Post: 22 December 2009 - 07:06 PM Rate Topic: -----

#1 vrichh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 21-December 09

CARD JAVA

Posted 21 December 2009 - 08:57 PM

I'm new to java, im currently working on my first assignment.
And just so all of you are aware, i am doing distance education(which was a terrible idea) I have asked my professor through email for some direction or advice and she then told me that i should think about dropping out of the course. Which was no help at all.

Anywho,
The assignment i am required to complete is this:

"Design a card class that contains a character data field to hold a suit ('s' for spades, 'h' for hearts, 'd' for diamonds, and 'c' for clubs) and an integer data field for a value from 1 to 13. Include, get and set methods for each field."

The second part of the assignment asks this of me:

"Write an application that randomly selects two playing cards and prints their values. Simply assign a suit to each of the cards, but generate a random number for each card's value."

As i stated before, i'm simply looking for some direction.
I honestly have no idea where to start and im not getting any help or direction from my professor.

Any advice or help would be very appreciated.
Thank you very much.
Vanessa.

Is This A Good Question/Topic? 0
  • +

Replies To: CARD JAVA

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10180
  • View blog
  • Posts: 37,586
  • Joined: 27-December 08

Re: CARD JAVA

Posted 21 December 2009 - 09:05 PM

You might take a look into using the java.util.Random class for your random numbers:
http://java.sun.com/...til/Random.html

As for the rest of the assignment, it should be pretty self-explanatory. You might want to review your lessons on OOP.

If you need help with the code you've written for this assignment, feel free to post. Remember to include that code.

Sorry we can't be of more assistance, but it would be in violation of the rules.
Was This Post Helpful? 0
  • +
  • -

#3 HunterE30633  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 21-October 09

Re: CARD JAVA

Posted 21 December 2009 - 10:09 PM

View Postvrichh, on 21 Dec, 2009 - 07:57 PM, said:

I'm new to java, im currently working on my first assignment.
And just so all of you are aware, i am doing distance education(which was a terrible idea) I have asked my professor through email for some direction or advice and she then told me that i should think about dropping out of the course. Which was no help at all.

Anywho,
The assignment i am required to complete is this:

"Design a card class that contains a character data field to hold a suit ('s' for spades, 'h' for hearts, 'd' for diamonds, and 'c' for clubs) and an integer data field for a value from 1 to 13. Include, get and set methods for each field."

The second part of the assignment asks this of me:

"Write an application that randomly selects two playing cards and prints their values. Simply assign a suit to each of the cards, but generate a random number for each card's value."

As i stated before, i'm simply looking for some direction.
I honestly have no idea where to start and im not getting any help or direction from my professor.

Any advice or help would be very appreciated.
Thank you very much.
Vanessa.




Lol, I'm a java tutor and a professor that I work with assigns that project to her students every quarter. Whats your teachers name?

But this is what you would need to do,

You need to create a card class that holds a 2 private variables, one for suit and rank, whatever data type is up to you. What I always suggest to my tutees is to create a constructor that accepts 2 int parameters, first one is for suit and should only by 1-4 and the next one is rank which should be 1-13. Then the constructor takes care of those numbers and processes them into a suit and rank such as Ace of Spades. Or you can take care of determing the suit and make the constructor accept a char and an int

So basically, all you need to do is use that concept, create two cards, create a toString method so you can throw it in:
System.out.println(card1);



and so on

This post has been edited by HunterE30633: 21 December 2009 - 10:10 PM

Was This Post Helpful? 0
  • +
  • -

#4 vrichh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 21-December 09

Re: CARD JAVA

Posted 22 December 2009 - 03:39 PM

View PostHunterE30633, on 21 Dec, 2009 - 09:09 PM, said:

View Postvrichh, on 21 Dec, 2009 - 07:57 PM, said:

I'm new to java, im currently working on my first assignment.
And just so all of you are aware, i am doing distance education(which was a terrible idea) I have asked my professor through email for some direction or advice and she then told me that i should think about dropping out of the course. Which was no help at all.

Anywho,
The assignment i am required to complete is this:

"Design a card class that contains a character data field to hold a suit ('s' for spades, 'h' for hearts, 'd' for diamonds, and 'c' for clubs) and an integer data field for a value from 1 to 13. Include, get and set methods for each field."

The second part of the assignment asks this of me:

"Write an application that randomly selects two playing cards and prints their values. Simply assign a suit to each of the cards, but generate a random number for each card's value."

As i stated before, i'm simply looking for some direction.
I honestly have no idea where to start and im not getting any help or direction from my professor.

Any advice or help would be very appreciated.
Thank you very much.
Vanessa.




Lol, I'm a java tutor and a professor that I work with assigns that project to her students every quarter. Whats your teachers name?

But this is what you would need to do,

You need to create a card class that holds a 2 private variables, one for suit and rank, whatever data type is up to you. What I always suggest to my tutees is to create a constructor that accepts 2 int parameters, first one is for suit and should only by 1-4 and the next one is rank which should be 1-13. Then the constructor takes care of those numbers and processes them into a suit and rank such as Ace of Spades. Or you can take care of determing the suit and make the constructor accept a char and an int

So basically, all you need to do is use that concept, create two cards, create a toString method so you can throw it in:
System.out.println(card1);



and so on




My professor's name is Kerri Shields, out of Ontario Canada.
The question is from "Java Programming" by Joyce Farrell, fifth edition
I know i probably sound ridiculous for asking about such simple tasks, im just completely lost:)

Thank you all, any other info would be very generous.
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: CARD JAVA

Posted 22 December 2009 - 03:43 PM

View Postvrichh, on 22 Dec, 2009 - 02:39 PM, said:

My professor's name is Kerri Shields, out of Ontario Canada.
The question is from "Java Programming" by Joyce Farrell, fifth edition
I know i probably sound ridiculous for asking about such simple tasks, im just completely lost:)

Thank you all, any other info would be very generous.

You mean you haven't seen in class a bsic class with getter() and setter() ?
And we are in December, at the end of the trimester
Was This Post Helpful? 0
  • +
  • -

#6 vrichh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 21-December 09

Re: CARD JAVA

Posted 22 December 2009 - 03:57 PM

View Postpbl, on 22 Dec, 2009 - 02:43 PM, said:

View Postvrichh, on 22 Dec, 2009 - 02:39 PM, said:

My professor's name is Kerri Shields, out of Ontario Canada.
The question is from "Java Programming" by Joyce Farrell, fifth edition
I know i probably sound ridiculous for asking about such simple tasks, im just completely lost:)

Thank you all, any other info would be very generous.

You mean you haven't seen in class a bsic class with getter() and setter() ?
And we are in December, at the end of the trimester



No? i haven't
My course goes from december until the end of march.
Was This Post Helpful? 0
  • +
  • -

#7 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: CARD JAVA

Posted 22 December 2009 - 04:20 PM

Get and Set methods are simply ways of either retrieving or changing the values of private or protected Objects within a class.

For instance:
class A
{
	 private int x;
	 private int y;
	 //constructor, and all that good stuff
	  
	 public int getX() //legal, since the class is able to access its own variables and manipulate them
	 {
		  return x;
	  }
	  public void setY(int a) //change the value of y
	  {
		   y = a;
	   }
}

//somewhere outside of the class
A obj = new A();
int a = obj.x; //illegal. x is private
int a = obj.getX(); //legal, the getX method is public

obj.y = 4; //illegal, y is private
obj.setY(4); //legal


I would suggest looking up a tutorial on Java classes as a refresher.
Was This Post Helpful? 0
  • +
  • -

#8 vrichh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 21-December 09

Re: CARD JAVA

Posted 22 December 2009 - 06:51 PM

I DON'T EVEN KNOW WHERE TO START.

I have public class Card, and public static void main(String[] args) and THAT IS IT!
I need some serious help.
Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: CARD JAVA

Posted 22 December 2009 - 07:06 PM

http://www.dreaminco...topic110380.htm
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1