aspose file tools*
The moose likes Beginning Java and the fly likes Meep Burrow (Ordering int) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Meep Burrow (Ordering int)" Watch "Meep Burrow (Ordering int)" New topic
Author

Meep Burrow (Ordering int)

Aj Prieto
Ranch Hand

Joined: Sep 28, 2012
Posts: 72

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.


Da mihi sis bubulae frustum assae, solana tuberosa in modo Gallico fricta ac quassum lactatum coagulatum crassum.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Sep 28, 2012
Posts: 72

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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Sep 28, 2012
Posts: 72

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

Joined: Oct 02, 2003
Posts: 10916
    
  12

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Aj Prieto
Ranch Hand

Joined: Sep 28, 2012
Posts: 72

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

Joined: Oct 02, 2003
Posts: 10916
    
  12

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

Joined: Sep 28, 2012
Posts: 72

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.).
 
Don't get me started about those stupid light bulbs.
 
subject: Meep Burrow (Ordering int)
 
Similar Threads
equals()
how to write the game-CrossingRiver (2)
HashMap
Clarification on Q6 Self-Test Chapter 3 K&B SCJP5
Logical operator precedence