# Maximum PC

 It is currently Sat Apr 18, 2015 5:17 pm

 All times are UTC - 8 hours

 Page 1 of 1 [ 9 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Question about my Java Program for Computer SciencePosted: Thu Feb 05, 2009 2:01 pm
 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 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++;
}
}
}

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

 Post subject: Posted: Fri Feb 06, 2009 5:29 am
 Java Junkie

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24241
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

 Post subject: Posted: Fri Feb 06, 2009 5:32 am
 SON OF A GUN

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

 Post subject: Posted: Fri Feb 06, 2009 7:44 am
 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

 Post subject: Posted: Fri Feb 06, 2009 8:19 am
 SON OF A GUN

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

 Post subject: Posted: Fri Feb 06, 2009 9:20 am
 Java Junkie

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24241
Location: Granite Heaven

Top

 Post subject: Posted: Fri Feb 06, 2009 9:38 am
 SON OF A GUN

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

Consider yourself a programming genius.

Top

 Post subject: Posted: Sat Feb 07, 2009 11:07 am
 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

 Post subject: Posted: Mon Feb 09, 2009 4:58 am
 SON OF A GUN

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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 9 posts ]

 All times are UTC - 8 hours

#### Who is online

Users browsing this forum: No registered users and 4 guests

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

Search for:
 Jump to:  Select a forum ------------------ Maximum FAQs    Forum Rules, Posting Guidelines & Announcements    The Good, The Bad & The Banned    FAQs Help/Do It Yourself    PC Building Lab    The Help Desk    PC Modding    Education & Certification Hardware    Nuts & Bolts    Portable Talk    Appraisals, Deals & Bargains (oh my!) OS/Software/Programming    Windows Parlor    Alt.OS.Abode    Games Arena    Programmers' Paradise Networking/Internet    Internet Truckstop    Network Nook In/Out    Magazine and Book Feedback    Forum & Website Feedback    Dog Pound Team Maximum PC Folding at Home    Team Maximum PC - Folding at Home - FIND CURES TO DISEASES    Team MPC - Folding Gauntlets