Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How do you write an advanced mutator method for arrays?

  1. #1
    Junior Member
    Join Date
    Apr 2020
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do you write an advanced mutator method for arrays?

    0


    I'm relatively new to programming, so this is very confusing to me. In this program, I declared and instantiated an array of 5 card EMPTY SLOTS (from a program called Card.java in which all the cards are complete). This is my constructor method:

    public BasicPlayer()
    {
    myHand = new Card[5];
    }


    Then I'm supposed to declare an advanced mutator and accessor method for arrays (the getter and setter I assume), which is where I am stuck. For the accessor method, I am supposed to get a card from the players hand:

    public Card getCard()
    {
    card tempCard = myHand [numberDealt];
    numberDealt ++;
    return tempCard;
    }

    but then for the mutator method, I am supposed to set a SINGULAR CARD into the player's hand (I will create a loop in a different class setting more cards into the hand, but for now, I just need one). This is where I am stuck. What am I supposed to do?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How do you write an advanced mutator method for arrays?

    supposed to set a SINGULAR CARD into the player's hand
    What is a SINGULAR CARD?
    If the player's hand has 5 slots, which slot is the card supposed to go into?

    an advanced mutator and accessor method for arrays
    You appear to have the accessor method. What is the advanced mutator method supposed to do?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Using a mutator method to set data to an array element
    By MrPigeon in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 2nd, 2014, 08:50 AM
  2. Mutator method at Beginner level
    By Huntea in forum Java Theory & Questions
    Replies: 3
    Last Post: January 30th, 2014, 07:47 AM
  3. Help with beginner mutator method
    By Dysun in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 8th, 2012, 06:32 PM
  4. What is the matching mutator method?
    By ssmith in forum Object Oriented Programming
    Replies: 1
    Last Post: November 3rd, 2009, 10:03 PM

Tags for this Thread