File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Ecosystem project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Ecosystem project" Watch "Ecosystem project" New topic

Ecosystem project

Jim Brownell

Joined: Mar 24, 2013
Posts: 2
I've been working on a project in my beginning java class called ecosystem. basically there is a 12x12 plott of land where each plot can contain up to 3 units: grass, tree, deer and there are also limits to each number of units on the grid at any one time. Where I'm getting hung up (no code yet) in my mind is how to visualize the solution. So have a few questions, not looking for code yet, just suggestions on how to implement. I'm sure the code questions will come later

1) i started out thinking the overall container for this exercise would be a 12x12 array would be the ecosystem
2) I would have a Class called Ecosystem which would create the ecosystem (12x12) array of ecosystem
3) 3 other classes would be Grass, Tree, and Deer and each instance would live in the grid.

I believe the array in ecosystem can carry objects in the array? yes?
If so, then this model would allow for 1 object per intersection yes?
to get multiple objects in each intersection, could i create HashMap as the instance in the array? This way I could have multiple objects referenced by each intersection?

Lets start with that, fire away

Like I said, just trying to understand better how this can be conceptualized before I start moving down this path with code

thank you.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

First....STOP thinking about arrays, classes, Objects, and java. just think about the problem. For example.

you need plots of land.
Each plot of land can contain what exactly? perhaps it is something like 1 deer (or not), 1 tree (or not) an one grass (or not). Does the grass/tree/deer have behavior associated with it? If it doesn't, you may not need a class for it.

Then you have a field, which holds all the plots. There is some limit to the number of deer in the field. this means that you need some way to check for the total number of deer before adding another. same for trees and grass?

Flesh out the above. Again, don't think in terms of Java and what it can do, think in English and what you need to do.

Once you've got that done, THEN go back and look for what exists in java that helps you do what you need.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jim Brownell

Joined: Mar 24, 2013
Posts: 2
Okay, i have been thinking about it and ended up there, even drew it out on paper to try and understand, that's where I came up with this structure. to answer your comment

the field is fixed and has 144 plots laid out in a 12x12 grid
each plot can contain multiple instances of grass, trees and deer on each plot
each plot can only contain 10 instances of vegetation (either grass or trees and unlimited number of deer as long as the land can support the deer
On each turn
grass grows every 2 turns
reproduces in it's own square or any adjacent square (if not full)
grass does not die, just eaten
trees grow every 5 turns
reproduces in it's own square or any adjacent square (if not full)
trees do not die, just eaten
deers eat grass (1 unit) and trees (1 unit) to stay healthy
max 8 units, decreases each turn and increases upon eating grass or trees
deer population doubles every 4 turns
deer can move one space in any direction on each turn
deer die when health is = 0

I believe after this exercise, my original questions are the same.

thank you
I agree. Here's the link:
subject: Ecosystem project
It's not a secret anymore!