#1
  1. User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Location
    UK
    Posts
    468
    Rep Power
    73

    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.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    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

IMN logo majestic logo threadwatch logo seochat tools logo