Posted: Sun Jul 18, 2004 11:36 am Post subject: method in a method
Is it possible to call a method inside another method?
I'm making a black jack game and i have one method to choose my card another one to tell them what card they have.
My program looks something like this. Only the methods are shown.
code:
public class blackJack {
public blackJack() {}
public int pickCard() {
// stuff in here
}
public void cardInfo() {
// info about cards goes on here with JOptionPane
// check if pickCard is an ace
// if it is then it asks user to pick 1 or 11
// should change the card variable to 1 or 11
}
public static void main (String[] args) {
// more stuff
}
}
Don't worry i have all my variables and stuff set. But im wondering if my card variable (the one i use for storing the number of the random chosen card) should be in the pickCard method or above it.
Please help
Sponsor Sponsor
wtd
Posted: Sun Jul 18, 2004 2:34 pm Post subject: (No subject)
You'll most likely want the card to be represented by an instance variable.
code:
// Note: in Java, class names begin with a capital letter
public class BlackJack {
public class Card {
public static final int HEART = 1;
public static final int DIAMOND = 2;
public static final int SPADE = 3;
public static final int CLUB = 4;
public static final int ACE = 1;
public static final int JACK = 10;
public static final int QUEEN = 11;
public static final int KING = 12;
private int suit;
private int value;
public Card(int suit, int card) {
this.suit = suit;
this.value = value;
}
public int getSuit() {
return suit;
}
public int getValue() {
return value;
}
}
public class Hand {
private Card[] cards;
public Hand() {
cards = new Card[5];
}
}
public class Game {
private Hand dealer;
private Hand player;
public Game() {
dealer = new Hand();
player = new Hand();
}
public Hand getDealer() {
return dealer;
}
public Hand getPlayer() {
return player;
}
}
}
Sort of like that.
Delta
Posted: Sat Jul 24, 2004 7:58 am Post subject: (No subject)
Quote:
Is it possible to call a method inside another method?
Yes it is... but as far as declaring one inside of another... I don't believe so
With your program there is no need to declare a method inside a method... it's useless... Have a nice day
LiquidDragon
Posted: Sat Jul 24, 2004 5:37 pm Post subject: (No subject)
Ok my black jack is all finished. I'm just gonna try to add some pictures and make it more interactive. Maybe even worthy of the web