Im having some trouble with my code:
It is supposed to display a sequence of letters based on whether a man jumps off a cliff or not. The equation used for the jump is listed as fStep . Heres the code:
import java.util.* ; class manDiving { public static void main(String args[]) { Scanner input = new Scanner (System.in); int tMax = 0 ; //Total time for the jump System.out.println("Man Jumping off a cliff !"); System.out.println("__________________________") ; System.out.println(" "); System.out.println("Please enter the maximum time in seconds"); tMax = input.nextInt(); calcDive(tMax); } public static void calcDive(int tMax) { char[] moves = new char[tMax] ; double cliffDistance = 0; //The man starts at 0.This is the distance he covered. double fStep ; // The probability of making the forward step. double random ; //Random Number generated to determine the sequence. int mLength = moves.length ; for(int counter = 0 ; counter < mLength ; counter++ ){ random = 0.0 + (int)(Math.random()*((1-0)+1));; fStep = 1 - (cliffDistance/10) ; if ( random < fStep ){ moves[counter] = 'F'; cliffDistance+=2 ; // Adds two feet to the distance. } else if ( random > fStep) { moves[counter] = 'B'; cliffDistance-- ; } } if ( cliffDistance == 10){ moves[moves.length-1] = 'D' ; System.out.print("The Man jumped after this succession of moves:"); for (int counter = 0 ;counter <mLength - 1 ; counter ++ ) { System.out.print (moves[counter]) ; } } else{ System.out.print("The man lost his nerve after this succession of moves:"); for(int counter = 0 ; counter<mLength ; counter++) { System.out.print(moves[counter]) ; } } } }
Im having multiple errors here and I want to be able to display the sequence here properly . The letter D , which indicates whether he dives or not doesnt display. What displays is a bunch of blanks.
Could anyone help please!
Much appreciated !
Heres the question itself too , for good measure :
Assume a man is preparing to dive, as shown in the following picture. The man needs to
move 10 feet forwards to go over the edge.
The man takes one step every second, and each step moves him two feet. He may,
however, not always move forward. Because he is nervous, he may step backwards,
particularly as he gets near the edge. The probability that the man will take a step forward
is given by :
P(forward) = 1- (x/10)
where x is the man’s distance (in feet) from his starting point
Note that, when x is 0 (man at his starting point), the man is certain to move forwards, but
that, when x is 8 (the man is on the brink of going over the edge), the probability of him
moving forwards is just 0.2. Note also that, if the man does not go forwards, he goes
backwards. If the man does not go over the edge within tMax secs, he doesnt go at al .