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