Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program should predict the size of a population of organisms. The class sho

ID: 3648365 • Letter: T

Question

This program should predict the size of a population of organisms. The class should store the starting number of organisms, their average daily population increase (as a percentage), and the number of days they will multiply. The class should have a method that uses a loop to display the size of the population for each day. I am having problems with calculating the dailyIncrease. import java.text.DecimalFormat; import java.util.Scanner; public class Population3 { public static void main(String[] args) { int startPop; //starting number of population int days; //number of days they will multiply double dailyIncrease; //average daily increase double temp; //holds variable DecimalFormat formatter = new DecimalFormat("#0%"); Scanner keyboard = new Scanner(System.in); System.out.println("Enter starting number of organisms:"); startPop = keyboard.nextInt(); System.out.println("Enter average daily population increase:"); dailyIncrease = keyboard.nextFloat(); System.out.println("Enter number of days for them to multiply:"); days = keyboard.nextInt(); if (startPop < 2) { System.out.println("Error: enter a number greater than 2"); System.exit(0); } if (dailyIncrease < 0) { System.out.println("Error: enter a number greater than zero"); System.exit(0); } if (days < 0) { System.out.println("Error: enter a number greater than zero"); System.exit(0); } temp = startPop; dailyIncrease = (dailyIncrease)/100; for (int i = 0; i < days; i++) { System.out.println("Day " + i); System.out.println("Number " + temp); temp = temp * dailyIncrease; System.out.println(formatter.format(dailyIncrease)); } } }

Explanation / Answer

import java.util.Scanner; public class Population { public static void main(String[] a) { int startPopulation; int avgIncreasePop; int days; String input; char yesNo; int total; Scanner kb = new Scanner(System.in); Population P = new Population(); do{ System.out.print(" Enter no. of organisms: "); startPopulation = kb.nextInt(); System.out.print("Enter average daily growth no. "); avgIncreasePop = kb.nextInt(); avgIncreasePop = avgIncreasePop / 100; System.out.print("Enter no. of days for multiplying: "); days = kb.nextInt(); } while(startPopulation >= 2 || avgIncreasePop > 0 || days >=1); { System.out.println("(1)Enter ONLY positive numbers. " +"(2)Initial" + " populaton must be > 2. " + "(3)" + "Number of days > 1."); System.out.println("Would you like to enter the numbers again? "); System.out.print("Press Y for YES or N for NO: "); input = kb.next(); yesNo = input.charAt(0); } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote