California Coakcroach Programming Challenge


(Command-Line Ninja) #1

California has been having strange weather recently causing cockroaches to grow to be 1 inch by 3 inches and to have offspring at a rate of 53% per day (assume a cockroach reaches adulthood in a day). You did not notice the 4 cockroaches under the refrigerator in the kitchen. Design a Java program to determine how long (in weeks) it will take the 4 cockroaches to multiply such that they will completely cover your kitchen floor, which measures 30 by 40 feet, and the total number of cockroaches covering the kitchen floor.

Your output statement should say something like “A total of X cockroaches will fully cover my apartment floors in Y.X weeks.

import java.util.Scanner;
 
public class JoshuaFlores_Exam4 {
   public static void main(String[] args){
      Scanner input = new Scanner(System.in);
      int day = 1;
      int floor = 120; 
      int weeks = 7;
      int roachsize = 3;
      double formula = 0.53 * roachsize * 4; 
      double time = (0.53 * roachsize * 4)/(7);
      while (day = 1; day * weeks; day++){
         while(formula <= 120){
            formula++;
      }
     }
         System.out.println("A total of 4 cockaroaches will fully cover my apartment floors in weeks:" + time);
         
       
  }
}

#2

This seems like a nice challenge :smiley:. I’ll have a try at it with Python.


(oaktree) #3

There are a lot of weird practices going on in this code. I don’t speak Java but I know hardcoding when I see it, and you have a lot of it. It’s limiting.


(Command-Line Ninja) #4

Not my code xD I just reposted it. Dont blame me! :((((((


(oaktree) #5

Oh okay. Is that snippet marked as a solution?


(Command-Line Ninja) #6

This topic was automatically closed after 30 days. New replies are no longer allowed.