public class BugTrouble2
1:
2: import java.util.Scanner;
3:
4: /**
5: Program to calculate how long it will take a population of
6: roaches to completely fill a house from floor to ceiling.
7: */
8: public class BugTrouble2
9: {
10: public static final double GROWTH_RATE = 0.95; //95% per week
11: public static final double ONE_BUG_VOLUME = 0.002; //cubic feet
12:
13: public static void main(String[] args)
14: {
15: System.out.println("Enter the total volume of your house");
16: System.out.print("in cubic feet: ");
17: Scanner keyboard = new Scanner(System.in);
18: double houseVolume = keyboard.nextDouble( );
19:
20: System.out.println("Enter the estimated number of");
21: System.out.print("roaches in your house: ");
22: int startPopulation = keyboard.nextInt( );
23: int countWeeks = 0;
24: int population = startPopulation;
25: double totalBugVolume = population * ONE_BUG_VOLUME;
26:
27: while (totalBugVolume < houseVolume)
28: {
29: int newBugs = (int)(population * GROWTH_RATE);
30: double newBugVolume = newBugs * ONE_BUG_VOLUME;
31: population = population + newBugs;
32: totalBugVolume = totalBugVolume + newBugVolume;
33: countWeeks++;
34: }
35:
36: System.out.println("Starting with a roach population of "
37: + startPopulation);
38: System.out.println("and a house with a volume of "
39: + houseVolume + " cubic feet,");
40: System.out.println("after " + countWeeks + " weeks,");
41: System.out.println("the house will be filled with " +
42: population + " roaches.");
43: System.out.println("They will fill a volume of " +
44: (int)totalBugVolume + " cubic feet.");
45:
46: System.out.println("Better call Debugging Experts Inc.");
47: }
48: }