473,776 Members | 1,650 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 #1
14 16844
Ganon11
3,652 Recognized Expert Specialist
So far, everything looks fairly OK. I'd like to point out a few things:

1) In your import statement, you say "import java.util.scann er;" but the class name is capitalized - it should be "import java.util.Scann er;". You made a similar mistake when creating your Scanner for input: "Scanner Keyboard = new scanner(System. in);" should be "Scanner Keyboard = new Scanner(System. in);"

2) Your problem specification calls for inputting a percentage for population increase. Right now, if you enter 1, the population will be doubled (because you increase dailyIncrease by 1, and in each 'day', the population is multiplied by dailyIncrease). You should reconfigure your program to treat dailyIncrease as a percentage by dividng it by 100 and storing it into a double before adding 1 to it.
Feb 16 '07 #2
neonman14
7 New Member
Thank you! So is there anything else I needs to change or add? If you don't mind me asking?!
Feb 17 '07 #3
Ganon11
3,652 Recognized Expert Specialist
Only that the first set of variables you create - int Size, Days, increase, number, Temp; and String input; are never used, so you can remove them.

Why don't you compile and run this to see if you're getting the correct results? You can come back with any errors you receive or faulty output, but right now I don't see anything wrong.
Feb 17 '07 #4
neonman14
7 New Member
So when I go add that change how will it look? I am confused how it should look!
Feb 17 '07 #5
Ganon11
3,652 Recognized Expert Specialist
All you will have to do is delete the first 6 lines from your main function where you declare 5 int variables and 1 string variable. These are the only places you use them, so they are the only lines you will have to remove.
Feb 17 '07 #6
neonman14
7 New Member
So it should look like this, right?

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)
{


//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 / 100;

for(int i = 0; i < numberOfDays; i++)
{
System.out.prin tln("Day " + i);
System.out.prin tln("Number " + temp);
Temp = Temp * dailyIncrease;
}
}
}
Feb 17 '07 #7
Ganon11
3,652 Recognized Expert Specialist
That code looks perfectly good to me. Have you tried compiling it and testing it?
Feb 17 '07 #8
neonman14
7 New Member
This is my errors after I compiled it

C:\Documents and Settings\Admini strator\My Documents\Popul ation.java:25: cannot find symbol
symbol : variable keyboardInput
location: class Population
startingSize = keyboardInput.n extInt(System.i n);
^
C:\Documents and Settings\Admini strator\My Documents\Popul ation.java:31: cannot find symbol
symbol : variable keyboardInput
location: class Population
dailyIncrease = keyboardInput.n extInt(System.i n);
^
C:\Documents and Settings\Admini strator\My Documents\Popul ation.java:44: cannot find symbol
symbol : variable Temp
location: class Population
Temp = Temp * dailyIncrease;
^
C:\Documents and Settings\Admini strator\My Documents\Popul ation.java:44: cannot find symbol
symbol : variable Temp
location: class Population
Temp = Temp * dailyIncrease;
^
4 errors

Tool completed with exit code 1
Feb 18 '07 #9
Ganon11
3,652 Recognized Expert Specialist
OK, the first two errors occur for the following reason: You declare your Scanner object as keyboard, but then refer to it is keyboardInput - the names don't match.

The second two errors occur because you declare your int variable as temp, but then refer to it as Temp - again, the names don't match.
Feb 18 '07 #10

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

Similar topics

1
2017
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
2080
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
2184
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
1375
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
2893
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
1999
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
4670
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
9464
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
10289
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10120
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...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8952
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...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
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();...
1
4031
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
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.