Note that there are some explanatory texts on larger screens.

plurals
  1. PORandomGenerator - Losing 50% of planes simulation
    primarykey
    data
    text
    <p>I'm working on a problem that I'm a little confused on. The question says imagine you're a general of the British Air Force during WW2. You have 100 planes left to defend the United Kingdom. With each mission you fly each plane has a 50% chance of getting shot down by the German anti aircraft guns so every mission you'll lose about half of your planes. You have to write a program that will approximate how many planes will survive after each mission and how many missions you can run until all your planes get shot down. <br/> <br/></p> <p>My program does not work and I don't know what wrong with it so I guess England is in trouble. I'm trying to solve this problem with two while loops. The outer while loop says as long as you have planes left send them on another mission. The inner while loop simulates the actual mission. After the while loop exists the total number of planes is now the surviving planes. </p> <pre><code>import acm.program.*; import acm.util.*; public class MissionPlanes extends ConsoleProgram{ public void run(){ int planes = 100; /* total number of planes */ int suvPlanes = 0; /* surviving planes */ int mission = 0; /* total number of missions */ int planeCounter = 0; /* keeps track of the planes flying over the anti plane gun */ while (planes &gt; 0){ while(planeCounter &lt; planes){ planeCounter++; if(rgen.nextBoolean()){ /* I've tried rgen.nextBoolean() with paramaters and with no paramaters */ suvPlanes += 1; } } planes = suvPlanes; mission++; println("The total number of surviving planes you have is " + planes + "after" + missoin + "missions"); } } private RandomGenerator rgen = RandomGenerator.getInstance(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload