Professional Documents
Culture Documents
ES205 Quiz1
ES205 Quiz1
ES205 Quiz1
ABDULLAH
/*
* 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;
}
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: