473,789 Members | 2,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Population program

7 New Member
Hello I am in Intro to Java Programming and I am having problems with assignment. The Homework assignment is called Population.

Population

Write a program that will predict the size of a population of organisms. The program should ask for the starting number of organisms, their average daily population increase (as a percentage), and the number of days they will multiply. For example, a population might begin with two organisms, have an average daily increase of 50%, and will be allowed to multiply for 7 days. The program should use a loop to display the size of the population each day.

Input Validation: Do not accept a number less than two for the starting size of the population. Do not accept a negative number for average daily population increase. Do not accept a number less than one for the number of days they will multiply.

Here is what I have done so far!

import java.util.scann er; // Needed for the scanner class




/**
This program demonstrates a user controlled loop
*/

public class Population

public static void main(String[] args)
{
int Size,
Days,
increase,
number,
Temp;
String input; // To Hold the user's input

//Create a Scanner object for keyboard input.
Scanner Keyboard = new scanner(System. in);


int startingSize = 0, dailyIncrease = 0, numberOfDays = 0;
int temp = 0;


//accept initial user input here

while (startingSize < 2)
{
System.out.prin t("Please enter a number that is greater than 1 for the population size: ");
startingSize = keyboardInput.n extInt(System.i n);
}

while (dailyIncrease < 0)
{
System.out.prin t("Enter a positive integer for the population size increase: ");
dailyIncrease = keyboardInput.n extInt(System.i n);
}

//do the same while loop for numberOfDays as a positive number > 0


temp = startingSize;
dailyIncrease = dailyIncrease + 1;

for(int i = 0; i < numberOfDays; i++)
{
System.out.prin tln("Day " + i);
System.out.prin tln("Number " + temp);
temp = temp * dailyIncrease;
}
Feb 16 '07
14 16846
neonman14
7 New Member
Thank you! I went and change that and yeah that is just me not paying attention! I went in and changed that and I went and compile it again ofter the chang and I got thes errors:

C:\Documents and Settings\Admini strator\My Documents\Popul ation.java:25: cannot find symbol
symbol : method nextInt(java.io .InputStream)
location: class java.util.Scann er
startingSize = keyboard.nextIn t(System.in);
^
C:\Documents and Settings\Admini strator\My Documents\Popul ation.java:31: cannot find symbol
symbol : method nextInt(java.io .InputStream)
location: class java.util.Scann er
dailyIncrease = keyboard.nextIn t(System.in);
^
2 errors

Tool completed with exit code 1
Feb 18 '07 #11
Ganon11
3,652 Recognized Expert Specialist
I don;'t think you need to pass System.in to each function of the Scanner - since you used System.in in the constructor, I think you can just use

Expand|Select|Wrap|Line Numbers
  1. startingSize = keyboard.nextInt();
Feb 18 '07 #12
neonman14
7 New Member
Thanks You! I cahnged that and it compiled good! But I don't think it doing what I need it to do!

When I compile it it just asks for a number greater then 1 in Population and after you type 2 or what every number it finished!

here is my compelte assignment with out any errors!

import java.util.Scann er; // Needed for the Scanner class

/**
This program demonstrates a user controlled loop
*/

public class Population
{
public static void main(String[] args)
{
int startingSize = 0, dailyIncrease = 0, numberOfDays = 0;
int Temp = 0;



//Create a Scanner object for keyboard input.
Scanner Keyboard = new Scanner(System. in);


//accept initial user input here

while (startingSize < 2)
{
System.out.prin t("Please enter a number that is greater than 1 for the Population Size: ");
startingSize = Keyboard.nextIn t();
}

while (dailyIncrease < 0)
{
System.out.prin t("Enter a positive integer for the Population Size Increase: ");
dailyIncrease = Keyboard.nextIn t();
}

//do the same while loop for numberOfDays as a positive number > 0


Temp = startingSize;
dailyIncrease = dailyIncrease / 100;

for(int i = 0; i < numberOfDays; i++)
{
System.out.prin tln("Day " + i);
System.out.prin tln("Number " + Temp);
Temp = Temp * dailyIncrease;
}
}
}
Feb 18 '07 #13
Ganon11
3,652 Recognized Expert Specialist
This is because of the way you initialize your variables before getting input. Your while() loop will continue while population increase is less than 0, but you initialize it to 0. You should refrain from giving your variables an initial value because you are using user input for all of them.

However, if you simply declare the variables without giving them a value, your while() loops will have some trouble. Change each while() loop to a do...while() loop to fix this. Also, don't forget to add the loop for numberOfDays - currently, you don't input into it, so the loop doesn't execute at all.
Feb 18 '07 #14
dexterdreads
5 New Member
so what was the final code for the population program? Did it work?
May 4 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2018
by: Eric O. Angell | last post by:
Say I have class Header: def __init__(self): self.foo = 0 # ... more fields and I have some commandline options that can specify better values for things in the header, such as foo. If I try the obvious (to me): parser = optparse.OptionParser() parser.add_option('--secret', type='string', dest='header', default=Header())
1
2081
by: Jane T | last post by:
is there someone who has used a tool to poplate a database schema with about 1M rows in the main table, where it is a controlled population (not strictly random)? we want to test our DB perf with an application, but we need meaningful data so that we can test for real-life scenarios. any help would be appreciated.
0
2185
by: Adisorn Ratanakovit | last post by:
When you set up a full-text catalog in SQL Server and you set up the population schedule, a job gets created and scheduled under SQL Server Agent. The problem I encountered recently is when I disabled that job in SQL Server Agent, the full-text catalog continues to be populated with that schedule (every 15 minutes). So I looked at the catalog's properties and noticed that the schedule is still marked as enabled. I deleted that schedule...
0
3029
by: Denise | last post by:
Hi I have set up a full text index on one of my database tables and created a catalog. Then I started a full population on my catalog and got a message "Population of full text index started successfully". However the catalog status has remained idle and its item count is 0. When i try to call on the full-text columns i get the following error message: -
0
3742
by: Megan | last post by:
Data Comparison: Sample Versus Rest of Population. I have a population of data, and I want to take a sample of that population and compare it against the entire population. I have a database that records information about the types of Rulings a person receives. Each person works for an agency, and there are 12 agencies (see example below). Each person receives a ruling, and there are 2 types of rulings,
1
1376
by: sam | last post by:
dear all, i've just finished a program which sets up an initial population consisting of four different phenotypes, allows them to evolve over time and graphs the output at the end, displaying what is in effect the evolutionary steady state for the system. i'm no authority on evolutionary game theory (to put it mildly), but there is a certain amount of interesting emergent behaviour if you put the initial parameters in in a certain...
3
2895
by: dexterdreads | last post by:
Hi, I have an assignment that is somewhat similar to the last guys: Write a class that will predict the size of a population of organisms. The class should store the starting # of ogranisms, their average daily population increase(as a percentage), and the number of days they will multiply. The class should have amethod that uses a loop to display the size of the population for each day. Test the class in a program that asks the user for...
1
2008
by: Clive Swan | last post by:
Hi I am trying to sum a population field that may have 140 records for each Ward (example). Any suggestions on the best way to do this. I would like to have a unique record for each Ward with all the records summed.
1
4671
by: tg | last post by:
http://img522.imageshack.us/img522/8647/scan10005ci7.jpg As a percentage of world inhabitants, the white population will plummet to a single digit (9.76%) by 2060 from a high-water mark of 27.98% in 1950. The big population story of the 21st Century is shaping up to be the status reversal of whites and blacks and the Indian baby boom. A side bar will be the single digit minority role that whites will assume. Of the 7 population groups...
0
9665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10199
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6768
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3697
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.