Hi, everyone! I was wondering if anyone can assist me with a problem that I have with my program. I have posted this problem before and took it off because I thought I finally got it. I did not realize however, that my main struggle was with the move() methods of the Deer and Hunter. I also did not realize that the program had to be an applet. I am really not familiar with java classes or applets that much. If anyone can assist me with the methods that I mentioned and the applet itself I would appreciate it. I have posted the document which has the requirements for the program and I have also posted what I have done so far(java file) on the zip file. I think I am pretty much done except for the two methods that I said earlier and the applet. Once again, I would appreciate it if anyone can help me with this. Thank you.
Hehe, didn't I say sjalle had something for you? Just a little patience...
BTW: have you noticed that this thread where you originally posted your problem and where you took it off has become the thread with the second most views, ie >1300?
So you know what I think public forums should be like AND can be good for + that completely deleting posts needs a VERY good reason...
: Beware of bugs in the above code - I have only proved it correct, not tried it.
completely deleting posts needs a VERY good reason
Till now, in my so far short career as moderator, I have never deleted any posts.
Here in Norway we have no problems with four letter words, not even
ten-letters, so anyone who curses/swears in desperation will be spared.
Flamers however, will get flushed, along with those that invite to immoral activity,
like cracking licenced software.
The specs are ok except for one vital detail, the hierachy restrictions.
I'll summarize:
We have a forest (grid) with creatures (grass, tree, deer, hunter) that
inhabitate the cells of the grid. The creatures can be subdivided into two
groups: fixed and moving creatures.
For me the natural approach is to regard the grid as the "world" (applet) and
then create a superclass:
Square: has only position and dimension, and possibly an inhabitant.
A bare implementation of this one is the Grass extension, but not very useful
(its a copy really) so instances of Square is "grass". The thing is that
the inhabitant, as an extension of Square, cannot use the Square's positional
data, - hunters or deers dont drag turfs of grass around....
Tree: a Square extension cannot be moved to (no Squirrels yet)
And here is my twist:
MovingCreature: an abstract Square extension, abstract methods
are move() and doAfterMoveAction(). MovingCreatures are alive or dead,
they can move (if alive), they have a time to reproduce and they die
according to specfic rules.
Deer: a MovingCreature extension, does not eat hunters, doesn't bother
eating (logically). Dies of age if not eaten. Hunter: a MovingCreature extension, eats Deers, must feed or die
The reason for my approach is this: we have a container of objects, and it will
complicate things if this container (forest) needs to know detailed info
about its creatures. Its should really just tell the moveable creatures to
"do their thing" at each tick. These "things" are moving and creature-
specific actions, like eat, die, feed, reproduce. I have put these actions
into the doAfterMoveAction() method of Deers and Hunters.
Using this approach the forest doesn't need to "know" anything more than
that a creature is a MovingCreature and then tell it to move and do its
specifics afterwards (doAfterMoveAction).
This may seem like an overkill, but it really isn't, try the other (assignment)
approach and I can guarantee that the code will be bloated in ceratin
areas and far less readable.
If we foresee an "enhanced" Forest with lions, cannibals,disease ridden
working girls (that won't plague the gay Hunters) plus some foot&mouth
viruses floating around, - then an abstract approach is a must.
I hope this is OK, I havent totally rehashed the assignment specs, all I have
done is inserting the MovingCreature abstract class between the Square
class and the Deers and Hunters, they are still subclasses of Square (and
MovingCreature).
I totally agree on what you are doing. It is definately ok and it would definately inprove the program structure and its usability. Thanks for speding the time and assisting me with my program. You can take your time in looking at all of the aspects and I will wait to see what you came up with once you are finished. Thanks once more for the help. I really appreciate it. Let me know when you get further on it. I just cannot picture in my mind on how the applet will run and make all of the objects on the screen move. Hope to hear from you. Talk to you then.
Till now, in my so far short career as moderator, I have never deleted any posts.
Here in Norway we have no problems with four letter words, not even
ten-letters, so anyone who curses/swears in desperation will be spared.
Flamers however, will get flushed, along with those that invite to immoral activity,
like cracking licenced software.
Ah no, sjalle, nothing that serious. I was just referring to none_none's deleting his own post in the thread now-known as "the minesweeper thread" ('the thread formerly known as "Help with Java program!"' = TTFKAHWJP, haha). You know, none_none and me, we've been having a little private conversation and in that I had emphasized that a public forum is at first - public.
Last edited by meisl; 04-27-2005 at 06:35 PM.
: Beware of bugs in the above code - I have only proved it correct, not tried it.
Hello, once more. Once again, just like before, I really appreciate the help that you have given me. You will be rewarded in the future and I know that for sure. Well, I tried to see the link that you posted but it did not show anything and therefore I looked at the code. I did what you told me and it did work. I have never compiled my programs like that so I was wondering if you could explain why it should be that way. I was wondering about why you should compile the folder name and then the Forest file(\javac forest\Forest.java). I know you said because of the package that you place at the beginning of the code but I am still not understanding that process. Is the forest package one that comes integrated in java or did you create that one yourself? Just wondering I am not sure if these questions are good or not but like I said, I have never dealt with something like this. Well, if you get the chance to answer these questions for me the I would appreciate it. Thanks once more for the help. I really appreciate it much. Talk to you later.
If you want to make a move into the modern world and use swing
(and above) then do the following (for IE):
Tools->Internet Options->advanced.
There you must check the option: Java (sun) -> use JRE 1.5.0 (something) .
If you can't find that option you must download the JDK from sun and install
it.
As for the package/folder issue, check out the sun documentation for this.
Oh.. and i seem to have switched the hunters and deers lifespan in the initialization,
just switch it back again.
Btw; Im doing this not only because i like to help people out,... I am building
myself an online library of java how-to examples and I will incorporate this
app/applet when its totally bug free and using images.
First and foremost, I really appreciate the help that you have given me. I looked over the program and tried to compile it but it did not compile. I have jcreator installed on my computer and ran it from there. I also ran it from the command line and this is what it gave me back on both (jcreator and command line):
D:\Final_Deer_Hunter\Forest.java:37: cannot resolve symbol
symbol : class Square
location: class forest.Forest
private Square [][] squares=null;
^
D:\Final_Deer_Hunter\Forest.java:43: cannot resolve symbol
symbol : class ForestPanel
location: class forest.Forest
private ForestPanel forestPanel = null;
^
D:\Final_Deer_Hunter\Forest.java:214: cannot resolve symbol
symbol : class Square
location: class forest.Forest
public Square [][] getSquares() { return squares; }
^
D:\Final_Deer_Hunter\Forest.java:332: cannot resolve symbol
symbol : class Creature
location: class forest.Forest
public void putForestCreature(Creature aCreature) throws Exception {
^
D:\Final_Deer_Hunter\Forest.java:156: cannot resolve symbol
symbol : class ForestPanel
location: class forest.Forest
forestPanel=new ForestPanel(this);
^
D:\Final_Deer_Hunter\Forest.java:313: cannot resolve symbol
symbol : class Hunter
location: class forest.Forest
Hunter aHunter=new Hunter(this, hunterTimeToReproduce,
^
D:\Final_Deer_Hunter\Forest.java:313: cannot resolve symbol
symbol : class Hunter
location: class forest.Forest
Hunter aHunter=new Hunter(this, hunterTimeToReproduce,
^
D:\Final_Deer_Hunter\Forest.java:314: cannot resolve symbol
symbol : class GridPosition
location: class forest.Forest
new GridPosition(), hunterTimeToLive);
^
D:\Final_Deer_Hunter\Forest.java:318: cannot resolve symbol
symbol : class Deer
location: class forest.Forest
Deer aDeer=new Deer(this, deerTimeToReproduce,
^
D:\Final_Deer_Hunter\Forest.java:318: cannot resolve symbol
symbol : class Deer
location: class forest.Forest
Deer aDeer=new Deer(this, deerTimeToReproduce,
^
D:\Final_Deer_Hunter\Forest.java:319: cannot resolve symbol
symbol : class GridPosition
location: class forest.Forest
new GridPosition(),
^
D:\Final_Deer_Hunter\Forest.java:324: cannot resolve symbol
symbol : class Tree
location: class forest.Forest
Tree aTree=new Tree(this, new GridPosition());
^
D:\Final_Deer_Hunter\Forest.java:324: cannot resolve symbol
symbol : class Tree
location: class forest.Forest
Tree aTree=new Tree(this, new GridPosition());
^
D:\Final_Deer_Hunter\Forest.java:324: cannot resolve symbol
symbol : class GridPosition
location: class forest.Forest
Tree aTree=new Tree(this, new GridPosition());
^
D:\Final_Deer_Hunter\Forest.java:340: package Square does not exist
aCreature.setBounds(row,col,Square.DIM.width, Square.DIM.height);
^
D:\Final_Deer_Hunter\Forest.java:340: package Square does not exist
aCreature.setBounds(row,col,Square.DIM.width, Square.DIM.height);
^
The system is out of resources.
Consult the following stack trace for details.
java.lang.OutOfMemoryError
Process completed.
From what you told me I know that you ran it successfully. Where did you run it? Do you know why it's giving me these errors? I have never seen the message at the end of these errors (The system is out of memory ... ) .Hope to hear from you soon. Thanks.
It runs allright, did you try the applet, the lin ki s in my post.
I guess this has to to with the folder you are keeping the source files in. The
source I posted has the package "forest" specified on top of the code. You should
make a folder of that name to compile them in
check this console output, it should give you the general idea
PS: for the "OutOfBrains" -exception, I get that sometimes too in JBuilder when I have
been crashing around for while. AND the Virus -class in my list is not a data virus. It is a little
contagious thing I was playing with in my program, it will work like :
virus class #1-5: reduces life expectancy by 10 to 50 %. and has a
probability of 10 to 50% for infecting neighbours
virus class #6-10: reduces life expectancy by 10 to 50 % and will infect all
neighbours of same species. Also - it is carried on to the offspring.
When I have my images ready this will look really nasty
Bookmarks