Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using only *JAVA 1 programming* create the following program -Create a program that will simulate the growth of a colony of insects. - The program

Using only *JAVA 1 programming* create the following program

-Create a program that will simulate the growth of a colony of insects. - The program should prompt the user for the number of starting insects, the percentage of daily population growth expected and the number of days that the simulation should run. - If an error occurs the user should be informed of the problem and be allowed to re-enter the data. The program should disallow the following: The program should not allow fewer than 2 insects to be entered. The program should not allow a growth level below 0%. The program should not run a simulation of less than 1 day in length. - After valid data has been input the program should calculate and print the number of insects in the colony during each day of the simulation

Using the code provide please fix and finish the last controlled loop for the calculations and output. -change varibles if needed -calculations should be close if not correct already.

public static void main(String []args)

{

Scanner input = new Scanner(System.in);

//Variables

int growth;

int currentDays;

int currentBugs;

int bugsAdded;

int numDay;

//input from science peeps

System.out.println("Please enter number of bugs on frist day: ");

currentBugs = input.nextInt();

System.out.println("Please enter expected daily growth percentage: ");

growth = input.nextInt();

System.out.println("Please enter number of days: ");

currentDays = input.nextInt();

//check loop for valid input

while (currentBugs <2 || growth <0 || currentDays <1)

{

System.out.println("Input error: "+

"There must be 2 or more bugs on day 1 "+

"The percentage of daily growth must be positive. "+

"The Simulation must run for at least 1 day. "+

"Try agian! ");

System.out.println("Please enter number of bugs on first day: ");

currentBugs = input.nextInt();

System.out.println("Please enter expected daily growth percentage: ");

growth = input.nextInt();

System.out.println("Please enter number of days: ");

currentDays = input.nextInt();

}

//math / output

do

{

bugsAdded = currentBugs * growth;

currentBugs = currentBugs + bugsAdded;

currentDays =1;

System.out.println("on day " + currentDays + "there will be " + currentBugs);

currentDays++;

}while (currentDays = numDay);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

mini-case insight into consumer decision making for TVs

Answered: 1 week ago