Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Name : NASHMER AILA SUMAIL

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package edu.msugs.msce205.quiz1;

/**
*
* @author KAMS
*/
public class ParachutistQuiz {
private static double g = 9.8; //m/s

//1st Method
public static double computeVelocityAtAnyGivenHeight(
double givenHeight, // in meters
double dragCoeffecient, // in Kg/s
double mass, // in Kg
double step, // in seconds
double initialVelocity) { // in km/s
double time = 0.0, lastTime = 0.0;
double velocity = initialVelocity;
double Displacement = 0.0;
while (true) {
if (Displacement <= givenHeight) {
velocity = velocity + (g - dragCoeffecient*velocity/mass)*step;
}
else break;
Displacement = velocity * time;
time = time + step;
}
return velocity;
}

//2nd Method
public static double computeElapsedTimeToGround(
double givenHeight,
double initialVelocity,
double dragCoeffecient,
double mass,
double step) {
double time = 0.0, lastTime = 0.0;
double velocity = initialVelocity;
double Displacement = 0.0;
while (true) {
velocity = velocity + (g - dragCoeffecient*velocity/mass)*step;
if (Displacement >= givenHeight) break;
else lastTime = time;
Displacement = velocity * time;
time = time + step;
}
return lastTime;
}

//3rd Method
public static double computeVelocityFromSpecifiedTime(
double initialVelocity,
double dragCoeffecient,
double mass,
double lastTime,
double step) {
double time = 0.0, specifiedTime = lastTime;
double velocity = initialVelocity;
while (true) {
if (time <= specifiedTime) {
velocity = velocity + (g - dragCoeffecient*velocity/mass)*step;
}
else break;
time = time + step;
}
return velocity;
}

public static void main(String[] args) {


double v1 = computeVelocityAtAnyGivenHeight(5000.0, 12.0, 70.0, .001, 0.0);
double v2 = computeVelocityAtAnyGivenHeight(1250.0, 12.0, 70.0, .001, 0.0);
double v3 = computeVelocityAtAnyGivenHeight(2500.0, 12.0, 70.0, .001, 0.0);
double v4 = computeVelocityAtAnyGivenHeight(3750.0, 12.0, 70.0, .001, 0.0);
double t2 = computeElapsedTimeToGround(5000.0, 0.0, 12.0, 70.0, .001);
double v5 = computeVelocityFromSpecifiedTime( 0.0, 12.0, 70.0, t2/4, .001);
double v6 = computeVelocityFromSpecifiedTime( 0.0, 12.0, 70.0, t2/2, .001);
double v7 = computeVelocityFromSpecifiedTime( 0.0, 12.0, 70.0, t2*3/4, .001);
String s1 = "The Parachutist reached the velocity of "
+ String.format("%.3f",v1) + " m/s after a displacement of "
+ String.format("%.3f",5.0) + " km right before it hits the ground";
System.out.println(s1);
System.out.println("\n \t *For other specified height, the velocity is:");
System.out.println(" \t height \t\t\t velocity");
String s2 = "\t 1/4 H \t\t\t\t " + String.format("%.3f",v2) + " m/s";
System.out.println(s2);
String s3 = "\t 1/2 H \t\t\t\t " + String.format("%.3f",v3) + " m/s";
System.out.println(s3);
String s4 = "\t 3/4 H \t\t\t\t " + String.format("%.3f",v4) + " m/s";
System.out.println(s4);

String s5;
s5 = "The Parachutist reached the ground after "
+ String.format("%.3f",t2) + " seconds";
System.out.println("\n" + s5);
System.out.println("\n \t *For other specified time, the velocity is:");
System.out.println(" \t Time \t\t\t velocity");
String s6 = "\t 1/4 T \t\t\t\t " + String.format("%.3f",v5) + " m/s";
System.out.println(s6);
String s7 = "\t 1/2 T \t\t\t\t " + String.format("%.3f",v6) + " m/s";
System.out.println(s7);
String s8 = "\t 3/4 T \t\t\t\t " + String.format("%.3f",v7) + " m/s";
System.out.println(s8);

}
}
OUTPUT:

You might also like