public class BugTrouble
1:
2: import java.util.*;
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 BugTrouble
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: public static void main(String[] args)
13: {
14: System.out.println("Enter the total volume of your house");
15: System.out.print("in cubic feet: ");
16: Scanner keyboard = new Scanner(System.in);
17: double houseVolume = keyboard.nextDouble( );
18: System.out.println("Enter the estimated number of");
19: System.out.print("roaches in your house: ");
20: int startPopulation = keyboard.nextInt( );
21: int countWeeks = 0;
22: double population = startPopulation;
23: double totalBugVolume = population*ONE_BUG_VOLUME;
24: while (totalBugVolume < houseVolume)
25: {
26: population = population + (GROWTH_RATE*population);
27: totalBugVolume = population*ONE_BUG_VOLUME;
28: countWeeks++;
29: }
30: System.out.println("Starting with a roach population of "
31: + startPopulation);
32: System.out.println("and a house with a volume of "
33: + houseVolume + " cubic feet,");
34: System.out.println("after " + countWeeks + " weeks,");
35: System.out.println("the house will be filled");
36: System.out.println("floor to ceiling with roaches.");
37: System.out.println("There will be " + (int)population + " roaches.");
38: System.out.println("They will fill a volume of "
39: + (int)totalBugVolume + " cubic feet.");
40:
41: System.out.println("Better call Debugging Experts Inc.");
42: }
43: }