Jail Broke out program.
Here I have written an assumption scenario, where a prisoner broke out the jail, This program show an approximate assumption how he crossed the two slippery walls of jail, one is of 9 meters and other as 10 meters.
Output:
Wall length :9 meters
1 Attempt
Jumped:5 meters
Slided: 1 meters
Climbed :4 meters
2 Attempt
Jumped:5 meters
Slided: 0 meters
Climbed :9 meters
Hurray! you've successfully crossed first wall.
Now get ready for second wall.
Second Wall length: 10 meters
1 Attempt
Jumped:5 meters
Slided: 1 meters
Climbed :4 meters
2 Attempt
Jumped:5 meters
Slided: 0 meters
Climbed :9 meters
3 Attempt
Jumped:5 meters
Slided: 0 meters
Climbed :14 meters
Wow! you've just broke the prison
Game Over get back to prison.
public class JailBrokeOut {
public static void getJumpCount(int input, int input2){
int attempt=0,jumped=5,slide=1,result=0;
System.out.println("Wall length :"+input+" meters \n");
if(input==9){do{
attempt++;
System.out.println(+attempt+ " Attempt \n");
result+=jumped-slide;
System.out.println("Jumped:"+jumped+ " meters");
System.out.println("Slided: "+slide+" meters");
slide--;
System.out.println("Climbed :"+result+" meters \n");
if(input==result){
System.out.println("Hurray! you've successfully crossed first wall.\n Now get ready for second wall. \n");
System.out.println("Second Wall length: "+input2+ " meters \n");
}
}while(attempt<2);
}
if(input2==10){ attempt=0;slide=1;result=0;
do{
attempt++;
System.out.println(+attempt+ " Attempt \n");
result+=jumped-slide;
System.out.println("Jumped:"+jumped+ " meters");
System.out.println("Slided: "+slide+" meters");
slide--;
if(slide<1){
slide=0;
}
System.out.println("Climbed :"+result+" meters \n");
}while(attempt<3);
if(result>=input){
System.out.println("Wow! you've just broke the prison \n Game Over get back to prison.");
}
}
}
public static void main(String [] args){
getJumpCount(9,10);
}
}
Output:
Wall length :9 meters
1 Attempt
Jumped:5 meters
Slided: 1 meters
Climbed :4 meters
2 Attempt
Jumped:5 meters
Slided: 0 meters
Climbed :9 meters
Hurray! you've successfully crossed first wall.
Now get ready for second wall.
Second Wall length: 10 meters
1 Attempt
Jumped:5 meters
Slided: 1 meters
Climbed :4 meters
2 Attempt
Jumped:5 meters
Slided: 0 meters
Climbed :9 meters
3 Attempt
Jumped:5 meters
Slided: 0 meters
Climbed :14 meters
Wow! you've just broke the prison
Game Over get back to prison.
Comments
Post a Comment