Hello, im new to this forum. I have an assignment for class that I am really confused with, please can you guys take a look and help me with the code or point me in the right direction, I am not asking anyone to do it for me...I ofcoarse wouldn't mind that :) but here's the assignment:

Objective: To practice using iteration and selection constructs in Java, and writing a class.

Write a class RabbitPopulation that simulates the growth of a rabbit population. The rules are as follows:

1. Start with one pair of rabbits (i.e., one male and one female)
2. Rabbits are able to mate at the age of one month. A month later, the female produces a pair of rabbits (one male, one female).
3. Assume that a female rabbit always produces a pair of rabbits every month from the second month on.
4. Assume that rabbits never die of old age.
5. Implement a method waitAMonth that updates the population as if one month passed.
6. Implement a method hunt that updates the population as if hunters killed 10 percent of the pairs (both immature and mature).
7. Implement a method getPairs that prints the current number of rabbit pairs.
8. Write a test program that shows the growth of the rabbit population for ten months in two situations:
in the case that no hunting occurs
in the case that hunting occurs once each month.

Hint: Keep one instance field for the newborn rabbit pairs and another one for the rabbit pairs that are at least one month old.

Thank you so much for taking the time to read it and helping me out...any help would be appreciated!

Do your own homework, we're not here to teach you that you can sit back on your lazy arse while others do your job for you.

Do your own homework, we're not here to teach you that you can sit back on your lazy arse while others do your job for you.

omg can u read?? didnt i say in there that im not asking u to do it for me.... :mad:

omg can u read?? didnt i say in there that im not asking u to do it for me.... :mad:

I think what jwenting was trying to say is... Give your best shot at your program and then ask for help on specific parts of your program.

Or you can wait until either freesoft 2000 or NPL see this thread, do your work for you and then try and get you to purchase stuff from them.

Regards,

Nate

I think what jwenting was trying to say is... Give your best shot at your program and then ask for help on specific parts of your program.

Or you can wait until either freesoft 2000 or NPL see this thread, do your work for you and then try and get you to purchase stuff from them.

Regards,

Nate

hahaha lmao...."free"soft 2000 and he wud try to get me to buy stuff...ironic aint it :cheesy:

r all u guys on here super java geniuses or just ppl lookin to bash on noobs! :D

r all u guys on here super java geniuses or just ppl lookin to bash on noobs! :D

No, I think most want to help new programmers that have at least tried to do their homework but run into some difficulty with it.

Some others do it for acceptance. Others do it to try and make a buck in the long run.

But not me. I'm different.

I do it to stroke my ego.

r all u guys on here super java geniuses or just ppl lookin to bash on noobs! :D

It's obvious you want your homework done for you.

Have you even tried yet? I haven't seen any work..

Money....? Sounds good.

I'll write this for you if you want to become my client. Looking forward to working with you!

hello server_crash, yes I have tried it.
Here is what I have so far:

Any help would be apreciated, u can see my assignment in the first post!
I would like to know what I would have to do next so far i was able to understand it!

public class RabbitPopulation
{
    private int rabbits;
    private int rabbitChild;
    public int adultRabbits;
    public int babyRabbits;

    public RabbitPopulation()
    {
        rabbits = 1;
        rabbitChild = 0;
        adultRabbits = rabbits;
        babyRabbits = rabbitChild;
    }

    public int waitAMonth()
    {
        int couple = adultRabbits;
        adultRabbits = adultRabbits + babyRabbits;
        babyRabbits = couple;
        rabbits = adultRabbits;
        return rabbits;
    }

    public int getPairs()
    {
        return rabbits;
    }

Edited 3 Years Ago by Nick Evan: Fixed formatting

From his own ramblings (rather than the stuff he copied word for word from his assignment, do they get those in electronic form nowadays?) it appears he needs some English language lessons first to understand the wording of the assignment...

And his reaction to people who tell him to show some effort show me he has some serious attitude problems as well.

Ignoring the rest of the program, I note that your constructor reads:

rabbits = 1;
rabbitChild = 0;
adultRabbits = rabbits;
babyRabbits = rabbitChild;
  • How will your 1 wabbit breed?
  • why do you need a temporary variables here?

please, think about these questions: don't guess code based on it. I think that if you actually sat down and thought about what the question was asking, you'd be able to do this in half an hour.

This advice was free.

From his own ramblings (rather than the stuff he copied word for word from his assignment, do they get those in electronic form nowadays?) it appears he needs some English language lessons first to understand the wording of the assignment...

And his reaction to people who tell him to show some effort show me he has some serious attitude problems as well.

I was thinking the same. Maybe he can try to get help from his teacher with the same attitude.

I was thinking the same. Maybe he can try to get help from his teacher with the same attitude.

wat r you guys talkin about...i have been talkin to u guys in a very nice manner!! maybe the words did not come out properly that led u ppl to believe that im showin attitude...anyway i do not want to get into that debate right now i need help with my assignment...

I counted 19 grammatical and spelling errors (including some nonexistent words and acronyms) in that 3 lines of text.
That's probably a new record for this site.

I counted 19 grammatical and spelling errors (including some nonexistent words and acronyms) in that 3 lines of text.
That's probably a new record for this site.

im busy with my program but am also tryin to imagine u with a personality..maybe you might be less boring once i get to know you, but i dont want to take that chance, bcz any friend of urs wud be a bad judge of character...but seriously though, i have come across rotten dog carcases that are less offensive to the senses than u r...maybe u wouldn't read like such a pathetic loser if u werent so dense that light bends around u...u know just my thoughts about u. u shudnt have gone about sayin idiotic stuff about my posts if u didnt want to help.

im busy with my program but am also tryin to imagine u with a personality..maybe you might be less boring once i get to know you, but i dont want to take that chance, bcz any friend of urs wud be a bad judge of character...but seriously though, i have come across rotten dog carcases that are less offensive to the senses than u r...maybe u wouldn't read like such a pathetic loser if u werent so dense that light bends around u...u know just my thoughts about u. u shudnt have gone about sayin idiotic stuff about my posts if u didnt want to help.

Uyo ear uipsdt.

hatch, the reason people are responding to you like that is that you don't seem to want to work with us. You have given very little of what the responders have asked for. You gave what little bit of code you had, which is good, but you have not explained what your specific problem is. If you come into a site, put down a project description, say that you want help without explaining what exactly it is that you are having a problem with, and sit back and wait, we will assume that you are sitting back and waiting for someone to give you all the code.

This may not make sense to you, but you need to look at it from our perspective. If you don't supply us with specific questions to answer, then you must be expecting us to just start throwing code at you. Since that is the case, it would seem that you want us to do the project for you. You say that is not what you want, so prove us wrong by asking questions: "I thought this was programming not Biology. How many rabbits are required for mating?", "Can I implement this entire program with just one class and one class instance or do I need to create a Population class to fill with all the created Rabbit instances?", "I've slept through most of my classes, so I understand the basics, but this program is way too much for me to handle all at once. Where should I start if I want to start small and then build up to the final project?", etc.

I noticed that you never replied to leelee's response to your code.

Do yourself and us a favor. Start working with us or find someone else to help you. This may be harsh, but it's reality. What we want is to help you and to help you in a way that will prevent you from coming back in two weeks asking for us to do your next assignment.

I'm writing this in perfect English so people who cannot understand how I write, can understand! LOL. I geuss what I wrote before made it sound like I wanted people to do it for me, which was not my intent. What was sad was that people actually started criticizing the way I wrote, this is a Java forum not an English spelling or English grammer forum. So here I go again, I understand most of what to do except how to write the hunt method. My assignment is in my first post so you guys can refer to it. Following is the code I wrote, I have included the hunt method but I am not sure if it is correct. Thank you. If you dont understand something, ask me I might be able to explain it in a better way.
What is wrong with my hunt method, if anything at all?
Feel free to tell me if I have made a mistake anywhere else.

class RabbitPopulation
{
private int adultRabbits;
private int babyRabbits;


public RabbitPopulation()
{
adultRabbits = 0;
babyRabbits = 1;
}


public void waitAMonth()
{
int babies = adultRabbits;
adultRabbits = adultRabbits + babyRabbits;
babyRabbits = babies;
}


public void hunt()
{
int dead = (adultRabbits + babyRabbits) * (10 / 100);
}


public int getPairs()
{
return babyRabbits + adultRabbits;
}
}

Edited 3 Years Ago by happygeek: fixed formatting

The logic of your program simply doesn't match your brief.

Read what it says in the brief, line by line, and match it to the code you have written.

Look at your Constructor again: the brief said you were to start with one pair of rabbits.

Your hunt method:
Write down a piece of paper, with a pen, exactly what you want your hunt method to do. You want it to do exactly what your brief suggests it should do. At the moment you are introducing a variable that is not linked in any way to the rest of the programme. Think about what you need it to do, then write the algorithm, then code.

Actually typing out the code should only be icing on the programing cake - the planning is the important bit.

Hah, ok look here guys, I have completed it but it still does not give me the right answer. It is not implementing my getHunt method for some reason. I would like to know what is wrong. You might ask what how I know the answer is wrong, well that's because I tried it without the getHunt method and got the same answer as I would with the getHunt method! Here is the code:

class RabbitPopulation
{
    private int adultRabbits;
    private int babyRabbits;

    public RabbitPopulation()
    {
        adultRabbits = 0;
        babyRabbits = 1;
    }
    
    public void waitAMonth()
    {
        int babies = adultRabbits;
        adultRabbits = adultRabbits + babyRabbits;
        babyRabbits = babies;
    }
    public int getPairs()
    {
        return babyRabbits + adultRabbits;
    }
    
    public int getHunt()
    {
        int dead = getPairs();
        dead = dead - (dead * (10 / 100));
        return dead;
    }
}

public class rabitPopulationTest
{
    public static void main(String[] args)
    {
        RabbitPopulation pop = new RabbitPopulation();
      
      pop.waitAMonth();
      System.out.print(pop.getHunt());
      System.out.println(" pairs");
      pop.waitAMonth();
      System.out.print(pop.getHunt());
      System.out.println(" pairs");
      pop.waitAMonth();
      System.out.print(pop.getHunt());
      System.out.println(" pairs");
      pop.waitAMonth();
      System.out.print(pop.getHunt());
      System.out.println(" pairs");
      pop.waitAMonth();
      System.out.print(pop.getHunt());
      System.out.println(" pairs");
      pop.waitAMonth();
      System.out.print(pop.getHunt());
      System.out.println(" pairs");
      pop.waitAMonth();
      System.out.print(pop.getHunt());
      System.out.println(" pairs");
      pop.waitAMonth();
      System.out.print(pop.getHunt());
      System.out.println(" pairs");
      pop.waitAMonth();
      System.out.print(pop.getHunt());
      System.out.println(" pairs");
      pop.waitAMonth();
      System.out.print(pop.getHunt());
      System.out.println(" pairs");
   }
}

So a little effort and your work pays off for you.

Good job.

The issue that you're having is, you're never actually removing the rabbits that are being hunted. The numbers that you're outputing are the number of rabbits being hunted. But you're never actually removing those hunted rabbits from the population.

Your hunt method also most likely shouldn't be returning anything and i'm not positive that its taking the right number of rabbits. (But i'm not positive.)

Here is the output that i get from making a few changes to your code...

Hunting...
2 pairs
4 pairs
8 pairs
16 pairs
31 pairs
59 pairs
113 pairs
215 pairs
409 pairs
778 pairs

No Hunting...
2 pairs
4 pairs
8 pairs
16 pairs
32 pairs
64 pairs
128 pairs
256 pairs
512 pairs
1024 pairs

Also, you migh want to use a for loop for your 10 months instead of writing out 10 waitMonths and hunts...

Now, i'm not positive that these numbers are correct, but based on the way rabbits do it... it should be close.

Regards,

Nate

One hint: name your fields in your classes to read what they actually mean.
When I read your code I assumed initially that you started out with a single rabbit because of the name of that field.

Hatch,

If I understand correctly,

--newborn rabbits must wait a month to mate and
mated rabbits must wait a month to make more babies(a pair)

--You start with a pair of newborn rabbits

Try running through a few months on paper
with just the basic rabbits (no hunter):

Month #1

NewBornRabbits - 2
MatingRabbits - 0
BabyMakinRabbits - 0

Month #2

NewBornRabbits - 0
MatingRabbits - 2
BabyMakinRabbits - 0

Month #3

NewBornRabbits - 2
MatingRabbits - 0
BabyMakinRabbits - 2

Month #4

NewBornRabbits - 2
MatingRabbits - 2
BabyMakinRabbits - 2

Month #5

NewBornRabbits - 4
MatingRabbits - 2
BabyMakinRabbits - 4

.....etc

You should see a pattern that will help
you decide on functions and algos.

Hope that helps! (without helping too much ;-)

OH, I am sorry guy's, I didn't recieve any emails that anyone replied so I didn't come back here, anyway, I made alot of changes to my program and finally got it to match the outputs of other fellow class mates. Here is the program if anyone cares.

//This class has:
// 1 Constructor
// 3 Methods
class RabbitPopulation
{
    //The instance variables:
    private int adultRabbits;
    private int babyRabbits;
    
    //The constructor
    public RabbitPopulation()
    {
        adultRabbits = 0;
        babyRabbits = 1;
    }
    
    //The method that makes the rabbits wait a month before mating.
    public void waitAMonth()
    {
        int babies = adultRabbits;
        adultRabbits = adultRabbits + babyRabbits;
        babyRabbits = babies;
    }
    
    //In this method I get the pairs first but then multiply it by two to make into a whole population without couples or pairs.
    public int getPairs()
    {
        int pairs;
        int single;
        pairs = babyRabbits + adultRabbits;
        single = pairs * 2;
        return single;
    }
    
    // This is my hunt method. It takes off 10% of the total population. I use the Math.round to get a rounded answer.
    public double getHunt()
    {
       double dead = 0;
       dead = getPairs() - Math.round(getPairs() * 0.1);
       return dead;
    }
}

//Following is the class that tests my RabbitPopulation class.
public class A1
{
    public static void main(String[] args)
    {
      RabbitPopulation rabPop = new RabbitPopulation();
      System.out.println("In case no hunting occurs each month"); 
      for (int x=1; x<=10; x++) //This is my for loop to get the population when no hunting has occured.
      {
      rabPop.waitAMonth();
      System.out.println(rabPop.getPairs());
      }
     
      RabbitPopulation rabPopH = new RabbitPopulation();
      System.out.println("In case hunting occurs each month");
      for (int x=1; x<=10; x++) //This is my for loop to get the population when hunting occurs each month.
      {
      rabPopH.waitAMonth();
      System.out.println(rabPopH.getHunt());
      }
}
}

I suggest that you paste your code into an IDE. The eclipse one would do fine free from eclipse.org The editor will help you identify any syntax problems and then you can go through the program one step at a time if you need too.

Have fun.

Hi everyone,

Or you can wait until either freesoft 2000 or NPL see this thread, do your work for you and then try and get you to purchase stuff from them.

Nate please remind me of which thread in which i did work for people and got people to buy stuff from me. Please remind me as i don't remember the thing you are accusing me of.

Yes i sometimes do homework for people but i never did once ask anyone to buy anything from me nor solicited any mode of payment nate. I do their homework so the sake of helping them out and not to get something in return.

Richard West
*****************************************************

This article has been dead for over six months. Start a new discussion instead.