Results 1 to 4 of 4
  1. #1
    royalcrown28 is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default First time poster looking for help accessing a variable from a separate class.

    A quick introduction,
    I am very new to java programming, i have only taken an intro java course at my university. Since then i have been trying for the most part to teach myself. My way of doing this was to create a bare-bones black jack program and slowly build upon it as i learn. I had a working code, but it was sloppy and only used the main method. Since i've learned a little more about method calls, i've been trying to break my existing code down into organised classes and methods.

    With that said,
    the current issue i am running into now is implementing a variable that exists in another class. now i know i am supposed to create an object of a class before i can use it, but the class i am trying to call is already made into an object by "main" and creating a second object in a different class causes undesired effects.

    Keeping in mind that i am very new and have limited knowledge of programming, i would like to find a work around for this issue. I'm taking baby steps right now.

    Here's the code that is causing my issue (i can post more of the code if needed, also i will attach the source package).

    Java Code:
    public class DealCard
    {
    Deck deck = new Deck();
    Random generator = new Random();
    boolean recieved;
    boolean pHasAce=false;
    boolean dHasAce=false;
    int dAce=0;
    int pAce=0;
    int card;
    int a=0;
    int b=0;
    boolean[] dealt = new boolean[52];
    public void dealDealer()
    {
    
    {
    recieved = false;
    while (!recieved)
    {
    card = generator.nextInt(51); 
    if (dealt[card]==false)
    {
    dealt[card]=true;
    deck.dealerHandCard[a] = deck.deck[card]; 
    deck.dealerHandValue[a] = deck.value[card];
    a++;
    recieved=true; 
    if (deck.value[card]==11)
    {
    dHasAce=true;
    dAce++;
    }
    
    }
    }
    
    }
    }
    ISSUE IS IN "PRINTERS" CLASS
    public class Printers
    {
    public void printPlayerHandString()
    {
    System.out.print("Player has ");
    for (int i=0; i<DealCard.b; i++)
    {
    System.out.print(playerHandCard[i]+" ");

    }

    }
    }
    Last edited by royalcrown28; 06-20-2012 at 07:27 AM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: First time poster looking for help accessing a variable from a separate class.

    Please be forthright when posting the same question to different forums. The response in your cross post at First time poster looking for help accessing a variable from a separate class. should explain the many reasons why

  3. #3
    royalcrown28 is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default Re: First time poster looking for help accessing a variable from a separate class.

    my mistake i thought these were different websites all together

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: First time poster looking for help accessing a variable from a separate class.

    Quote Originally Posted by royalcrown28 View Post
    my mistake i thought these were different websites all together
    They are different sites. Some folks navigate between them, many don't. Notifying folks you've posted in different sites keeps everyone on the same page, as opposed to maintaining discussions across sites - rehashing the same questions, or at worse having unpaid contributors answering a question already answered elsewhere (and in many of their minds, when finding out this to be the case feel cheated of their valuable time).
    Last edited by doWhile; 06-20-2012 at 08:10 AM. Reason: clarification

Similar Threads

  1. Replies: 5
    Last Post: 12-18-2011, 05:06 AM
  2. Modifying JLabel within separate class
    By the_rider9 in forum New To Java
    Replies: 6
    Last Post: 07-06-2011, 07:07 PM
  3. how to separate this code in another class
    By Jhovarie in forum AWT / Swing
    Replies: 5
    Last Post: 03-01-2011, 06:08 PM
  4. Accessing session variable from Java Class
    By Rohit Pokhrel in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 12-08-2010, 05:07 PM
  5. Replies: 6
    Last Post: 03-31-2009, 05:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •