Quantcast

Maximum PC

It is currently Fri Dec 19, 2014 6:47 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Question about my Java Program for Computer Science
PostPosted: Thu Feb 05, 2009 2:01 pm 
8086
8086

Joined: Thu Jun 12, 2008 1:41 pm
Posts: 37
Location: OH-IO
I'm in a intro to computer science course and are HW assignment is to create a program to simulate a rabbit population over so many months. I am having trouble with the part where I determine the gender of each rabbit for more than the first month. Here's what I have for determining gender...

Code:
public class TestMath
{
   public static void main( String[] args )
   {
      int mAdult = 0;
      int fAdult = 0;
       int mBaby = 1;
       int fBaby = 1
       int count = 1;
      int newBabies = fAdult + fbaby ;
      int month = 15;
      
         //determine gender for each baby rabbit
         while ( count <= newBabies )
         {
            double r = Math.random();
         
            if ( r < .5)
            male++;
         
            else
            female++;
         
            count++;
         }
      System.out.printf( "mAdult: %d\fAdult: %d", mAdult, fAdult);
   }
}


So that determines the gender of the rabbits after 1 month, but say I want to do it for 15 months. The assignment says each female rabbit produces 2 babies each month and after 1 month a baby becomes an adult. How would I do this for any number of months and then display the population?


Top
  Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 5:29 am 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24238
Location: Granite Heaven
We don't do homework correction here. We do help people understand the problem and help find elusive bugs .. but the code you've posted is too far from 'correct' for us to help you.

Here is a hint: throw out all of that code. Grab a piece of paper and a pen. Think about the problem. What happens in the first month? What happens in the second month? The third? How do you know?


Top
  Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 5:32 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
I am going to go with Jip on this one. I am totally confused by that code and I can't tell what you are trying to accomplish.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 7:44 am 
8086
8086

Joined: Thu Jun 12, 2008 1:41 pm
Posts: 37
Location: OH-IO
Yeah, I ended up writing it out on paper afterwards and I figured everything out. Sorry my coding attempts so bad, it is my first one and my professor is not very good, but I think I have it figured out how I should approach these from now on. I was just looking at it the wrong way. Also, I'll make sure next time I have all the code and that it is written clearly. You can go ahead a lock this thread now since it is of no use to anyone. But before you do that, could you recommend any good books that should be read on becoming a better programmer or something like that?


Top
  Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 8:19 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
You are more than welcome to post your solution (with or without code) for the benefit of others...

The thread can certainly be of use to others.

List of "must read" books / articles incoming... (After I go eat lunch :) )


Top
  Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 9:20 am 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24238
Location: Granite Heaven
You could start by reading the sticky threads in this folder.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 9:38 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
http://stackoverflow.com/questions/3164 ... g-articles

Consider yourself a programming genius. :P


Top
  Profile  
 
 Post subject:
PostPosted: Sat Feb 07, 2009 11:07 am 
8086
8086

Joined: Thu Jun 12, 2008 1:41 pm
Posts: 37
Location: OH-IO
Thanks for the link crashTECH I'll read some of their articles when I get some spare time.


Top
  Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2009 4:58 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Zipster41 wrote:
Thanks for the link crashTECH I'll read some of their articles when I get some spare time.
You might find this site VERY helpful to you.

http://www.topcoder.com/


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.