Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6749747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:43:38+00:00 2026-05-26T12:43:38+00:00

Background: my assignment was to write a program that uses linked list to keep

  • 0

Background: my assignment was to write a program that uses linked list to keep track of cards in a card game (war). So I wrote 4 programs: card.java, deckofcards.java, hand.java, war.java(driver). card holds basic info. When adding to a linked list of the cards I use a method called setLast:

nextCard=null;
public card(String a, String b)
{
    hand=a;
    suit=b;
}
public void setLast(card c)
{
    if(nextCard==null)
    {
         nextCard = c;
    }
    else
    {
         nextCard.setLast(c);
    }
}

then in deckofcards.java:

    card deck, dealt;
    public deckofcards()
{
    rand = new Random();
    dealt = new card("0","0"); //null card place holders
    first = new card("0","0");
    numcards = 52;
    shuffle();
}
    public card dealCard()
{
    card c=new card("0","0");
    if(first!= null)
    {
        c = first;
        first = first.nextCard;
        c.nextCard = null;
        if(dealt.toString().compareTo("00")==0)
        {
            dealt = c;
        }
        else
        {
            dealt.setLast(c);
        }
        numcards--;
    }
    else
    {
        System.out.println("Deck: ran out of cards");
    }
    return c;
}

so deckofcards generates 52 randomly(supposed to anyway, but thats a different question) ordered cards and hands deals them to instances of hand.java in war.java

hand.java:

    card cards;
    int numcards;
    public void getCard(card c)
{
    System.out.println("In hand.java,getCard");
    if (numcards==0)
    {
        cards = c;
        numcards++;
    }
    else
    {
        cards.setLast(c);
    }
}

and war.java:

    players = new hand[numplayers];
    for(int i=0;i<numplayers;i++)
{
    players[i] = new hand();
}
deck = new deckofcards();
int i=0;
while(i<52)
{
    int ii=0;
    if((ii<numplayers)&&(i<52))
    {
        players[ii].getCard(deck.dealCard());
        i++;
        ii++;
    }
    else
    {
        ii=0;
    }
}

output:
In hand.java,getCard
In hand.java,getCard
Exception in thread “main” java.lang.StackOverflowError
at card.setLast(card.java:125)
at card.setLast(card.java:125)
at card.setLast(card.java:125)
at card.setLast(card.java:125)
at card.setLast(card.java:125)
at card.setLast(card.java:125)
at card.setLast(card.java:125)
//repeated 1000s of times…

Of course I only provided the snippet of code I believe is causing the problem I can provide the whole code upon request.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:43:38+00:00Added an answer on May 26, 2026 at 12:43 pm

    Your list has a loop somewhere, i.e. “A->B->C->D->B”. Is there a reason you are using “null card placeholders” instead of the value null? I notice setLast is checking for the value ‘null’ instead of ’00’ for your null placeholder, but without seeing all the code it’s hard to tell where your list gets a loop at.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some background information, for a homework assignment I had to write a polish notation
Background: At my company we are developing a bunch applications that are using the
BACKGROUND: I'm writing a single level cache simulator in C for a homework assignment,
I'm coming to javascript from C background. In javascript, when I use the assignment
My boss has given me an assignment that I'm not sure is possible since
Consider the following code, which takes place in a background thread (thread B): List<T>
Hai Friends, I have developed an application which en-composes list views and posted that
Recently i got an assignment at school, where we are to write a small
I am trying to write source based on the Game Of Life simulation concept.
Background: I'm trying out the HelloPoly assignment in the CS193P course. I've created my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.