Results 1 to 2 of 2

Thread: Bigfoot Program

  1. #1
    stewartjc1 is offline Member
    Join Date
    Mar 2015
    Posts
    1
    Rep Power
    0

    Default Bigfoot Program

    Hello, I was wondering if anyone could tell me why my program does not iterate past my first simulation. Additionally, I am aware that my code is very tedious but I am a beginner. So this was the only way that I could understand it

    Java Code:
    public class Homework_5 
    {
    	public static void main(String[] args) 
    	{
    		//These are the declarations for most of my variables
    		int count_of_sims = 0;
    		int hours = 0;
    		int minutes = 0;
    		int photo_bigfoot = 0;
    		int count_of_photos = 0;
    		int sumOne = 0;
    		int sumTwo = 0;
    		int sumThree = 0;
    		int sumFour = 0;
    		int sumFive = 0;
    		int sumSix = 0;
    		int avg = 0;
    		double firstFly = 0.0;
    		double secondFly = 0.0;
    		double thirdFly = 0.0;
    		double fourthFly = 0.0;
    		double fifthFly = 0.0;
    		double sixthFly = 0.0;
    		
    		//This while loop performs all five simulations
    		while(count_of_sims < 4)
    		{
    			count_of_sims = count_of_sims + 1;
    			
    			//This while loop determines which fly of the forest our airplane is on
    			while(hours < 25)
    			{
    				hours = hours + 4;
    				//This is the first fly of the forest by our airplane
    				if(hours == 4)
    				{	
    					//This while loop determines which minute we are on in regard to taking photos of the bigfoot
    					while(minutes < 3)
    					{
    						minutes = minutes + 1;
    						//This is the first minute 
    						if(minutes == 1 && count_of_photos <=10)
    						{
    							firstFly = (int)(Math.random() *100) * .50;
    							photo_bigfoot++;
    							count_of_photos++;
    							sumOne = sumOne + photo_bigfoot;
    							System.out.println("Simulation 1: First Minute: Photos of bigfoot: " + firstFly + " of 240" + ", ");
    						}
    						//This is the second minute
    						else if(minutes == 2 && count_of_photos <=10)
    						{
    							firstFly = (int)(Math.random() *100) * .75;
    							photo_bigfoot++;
    							count_of_photos++;
    							sumOne = sumOne + photo_bigfoot;
    							System.out.println("Simulation 1: Second Minute: Photos of bigfoot: " + firstFly  + " of 240" + ", ");
    						}
    					}
    				}
    				//This is the second fly of the forest by our airplane
    				else if(hours == 8) 
    				{				
    					//This while loop determines which minute we are on in regard to taking photos of the bigfoot
    					while(minutes < 3)
    					{
    						minutes = minutes + 1;
    						//This is the first minute
    						if(minutes == 1 && count_of_photos <=10)
    						{
    							secondFly = (int)(Math.random() *100) * .50;
    							photo_bigfoot++;
    							count_of_photos++;
    							sumTwo = sumTwo + photo_bigfoot;
    							System.out.println("Simulation 2: First Minute: Photos of bigfoot: " + secondFly + " of 240" + ", ");
    						}
    						//This is the second minute
    						else if(minutes == 2 && count_of_photos <=10)
    						{
    							secondFly = (int)(Math.random() *100) * .75;
    							photo_bigfoot++;
    							count_of_photos++;
    							sumTwo = sumTwo + photo_bigfoot;
    							System.out.println("Simulation 2: Second Minute: Photos of bigfoot: " + secondFly + " of 240" + ", ");
    						}
    					}
    				}
    				//This is the third fly of the forest by our airplane
    				else if(hours == 12) 
    				{	
    					//This while loop determines which minute we are on in regard to taking photos of the bigfoot
    					while(minutes < 3)
    					{
    						minutes = minutes + 1;
    						//This is the first minute
    						if(minutes == 1 && count_of_photos <=10)
    						{
    							thirdFly = (int)(Math.random() *100) * .50;
    							photo_bigfoot++;
    							count_of_photos++;
    							sumThree = sumThree + photo_bigfoot;
    							System.out.println("Simulation 3: First Minute: Photos of bigfoot: " + thirdFly + " of 240" + ", ");
    						}
    						//This is the second minute
    						else if(minutes == 2 && count_of_photos <=10)
    						{
    							thirdFly = (int)(Math.random() *100) * .75;
    							photo_bigfoot++;
    							count_of_photos++;
    							sumThree = sumThree + photo_bigfoot;
    							System.out.println("Simulation 3: Second Minute: Photos of bigfoot: " + thirdFly + " of 240" + ", ");
    						}
    					}
    				}
    				//This is the fourth fly of the forest by our airplane
    				else if(hours == 16) 
    				{
    					//This while loop determines which minute we are on in regard to taking photos of the bigfoot
    					while(minutes < 3)
    					{
    						minutes = minutes + 1;
    						//This is the first minute
    						if(minutes == 1 && count_of_photos <=10)
    						{
    							fourthFly = (int)(Math.random() *100) * .50;
    							photo_bigfoot++;
    							count_of_photos++;
    							sumFour = sumFour + photo_bigfoot;
    							System.out.println("Simulation 4: First Minute: Photos of bigfoot: " + fourthFly + " of 240" + ", ");
    						}
    						//This is the second minute
    						else if(minutes == 2 && count_of_photos <=10)
    						{
    							fourthFly = (int)(Math.random() *100) * .75;
    							photo_bigfoot++;
    							count_of_photos++;
    							sumFour = sumFour + photo_bigfoot;
    							System.out.println("Simulation 4: Second Minute: Photos of bigfoot: " + fourthFly + " of 240" + ", ");
    						}
    					}
    				}
    				//This is the fifth fly of the forest by our airplane
    				else if(hours == 20) 
    				{
    					//This while loop determines which minute we are on in regard to taking photos of the bigfoot
    					while(minutes < 3)
    					{
    						minutes = minutes + 1;
    						//This is the first minute
    						if(minutes == 1 && count_of_photos <=10)
    						{
    							fifthFly = (int)(Math.random() *100) * .50;
    							photo_bigfoot++;
    							count_of_photos++;
    							sumFive = sumFive + photo_bigfoot;
    							System.out.println("Simulation 5: First Minute: Photos of bigfoot: " + fifthFly + " of 240" + ", ");
    						}
    						//This is the second minute
    						else if(minutes == 2 && count_of_photos <=10)
    						{
    							fifthFly = (int)(Math.random() *100) * .75;
    							photo_bigfoot++;
    							count_of_photos++;
    							sumFive = sumFive + photo_bigfoot;
    							System.out.println("Simulation 5: Second Minute: Photos of bigfoot: " + fifthFly + " of 240" + ", ");
    						}
    					}
    				}
    				//This is the sixth fly of the forest by our airplane
    				else if(hours == 24) 
    				{
    					//This while loop determines which minute we are on in regard to taking photos of the bigfoot
    					while(minutes < 3)
    					{
    						minutes = minutes + 1;
    						//This is the first minute
    						if(minutes == 1 && count_of_photos <=10)
    						{
    							sixthFly = (int)(Math.random() *100) * .50;
    							photo_bigfoot++;
    							count_of_photos++;
    							sumSix = sumSix + photo_bigfoot;
    							System.out.println("Simulation 6: First Minute: Photos of bigfoot: " + sixthFly + " of 240" + ", ");
    						}
    						//This is the second minute
    						else if(minutes == 2 && count_of_photos <=10)
    						{
    							sixthFly = (int)(Math.random() *100) * .75;
    							photo_bigfoot++;
    							count_of_photos++;
    							sumSix = sumSix + photo_bigfoot;
    							System.out.println("Simulation 6: Second Minute: Photos of bigfoot: " + sixthFly + " of 240" + ", ");
    						}
    					}
    				}
    			}
    		}
    		//Compute the average
    		avg = (sumOne + sumTwo + sumThree + sumFour + sumFive + sumSix) / count_of_sims;
    		
    		//Print average
    		System.out.println("Average photos taken of bigfoot: " + avg + " of 240");
    		
    	}
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Bigfoot Program

    It doesn't look to me like you reset hours after the inner loop finishes, so hours (after the first simulation) is always >= 25.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 6
    Last Post: 12-15-2013, 07:40 AM
  2. Replies: 4
    Last Post: 11-21-2012, 02:19 PM
  3. Replies: 2
    Last Post: 04-02-2011, 01:57 PM
  4. Replies: 13
    Last Post: 03-22-2011, 07:49 AM
  5. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 07:53 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •