• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Meep Burrow (Ordering int)

 
Aj Prieto
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I need some help with my assignment.

Here is a link to the assignment:
http://www2.hawaii.edu/~ztomasze/teaching/ics211/2012fa/hw/A06b.html

I'm having trouble with the "add" method. The "tiny" variable will not update and keep track of the "tiny Meep".

Here is my code (note: all the println statements are there to let me know what process it is going through.):


Here is one of the sample output (notice where TM (tiny meep) it says M4 rather than M1):


Thanks in advance.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most people won't want to read such a vast amount of text and code. If terminating a loop is your problem, you should trim the code down as much as possible to where you have nothing but that loop and a few print statements. Barring that (or in conjunction with it) you should add copious print statments so you can see what's happening at each step, and compare that to what you've worked out on paper should be happening.
 
Aj Prieto
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added print statements, and when it crashes, it tends to crash around this area:


I think what is happening is that the "tiny meep" is moving but the "tiny" variable is not keeping up with it.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You say it crashes, so I assume you're getting an exception with a stack trace. Copy/paste that complete error message please.
 
Aj Prieto
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's one:


And another



MeepBurrow.java:71 is:


This is what would happen if I made it print what it was doing:


And another:


MeepBurrow.java:48 is:


Thanks
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well...the first two are pretty obvious aren't they? Don't try and pop something off an empty stack. You should always check your stack before you pop anything off to prevent this.

It looks like you have tried to push M3 and M1 onto the stack, based on the printout, but clearly that isn't working.
 
Aj Prieto
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I realize that, but my question is how do I make sure that the "tiny" variable keeps up with the "tiny meep". It seems that once the third meep enters the burrow, "tiny" is always one step behind of "tiny meep".
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea what "tiny" is supposed to be. It seems like a horribly named variable, as does Meep.

Your link to the assignment doesn't work, so I don't know what any of this is supposed to do.

But, the advice I always give is this:

Put in lots of System.out.printnl() statements. Every time tiny changes, print the new value. every time you test to see what it is, print that. You have to understand what it is doing before you can fix what is wrong.
 
Aj Prieto
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops...Sorry, about that. I fixed it in the first post.

The tiny variable is supposed to keep track of the index of the tiny meep (creatures that live in burrows. They have a sense of social order and they stack themselves up in descending size.).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic