Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 14th, 2012, 05:43 AM
sephers181's Avatar
sephers181 sephers181 is offline
User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: UK
Posts: 467 sephers181 User rank is Second Lieutenant (5000 - 10000 Reputation Level)sephers181 User rank is Second Lieutenant (5000 - 10000 Reputation Level)sephers181 User rank is Second Lieutenant (5000 - 10000 Reputation Level)sephers181 User rank is Second Lieutenant (5000 - 10000 Reputation Level)sephers181 User rank is Second Lieutenant (5000 - 10000 Reputation Level)sephers181 User rank is Second Lieutenant (5000 - 10000 Reputation Level)sephers181 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 6 h 38 m 48 sec
Reputation Power: 72
Homework - Sending values from one class to another

Hi,
I'm creating a simulator for a game of rummy and I'm now stuck with dealing the cards. I have a class for each player:
Code:
class Player{
	private Card[] currentCards;

	public Player(){
		currentCards = new Card[8];
	}

	public void giveCard(int index, int value, char suit){
		currentCards[index] = new Card(value, suit);
	}

}

and I have another class called Deck that will basically create a deck of cards, shuffle them and then produce 7 values for each player from within that deck.

How can I take an integer value that is within a function inside the Deck class and send it to the function giveCard inside the Player class?

Thanks,
Sephers.
__________________

Reply With Quote
  #2  
Old November 14th, 2012, 07:49 AM
NormR's Avatar
NormR NormR is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,959 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 3 h 17 m 24 sec
Reputation Power: 345
One way for the giveCard() method to get a value from another class is to have a method in that other class that returns the value. giveCard() would need a reference to the other class so it could call the method:

int desiredValue = refToOtherClass.getDesiredValue(); // call method to get value

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Homework - Sending values from one class to another

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap