PLS I NEED HELP Description Java Your program should ask you
PLS I NEED HELP!
Description: Java
Your program should ask you to enter in the mass, cross-sectional area, and drag coefficient of the skydiver. Your program should also ask how long do you want to calculate the dive out to and what your timestep (t) will be. You can assume the density of air is 1.14 kg/m^3 and gravitational acceleration is 9.81 m/s^2. As your program does its calculations, it should save the time and velocities in an array (i.e., in two separate one-dimensional arrays, one for time and the other for velocities). One you have calculated all these values, write the output to a file. The file should have two columns, the first being the time (t) and the second being the velocity (v(t)) at that time. You can separate the two columns either by a space, tab, or comma; Excel can import files whose columns are separated by any of those characters. Your program, then, should also prompt you for the output filename. While the full output will go to a file, you should write out a few values to screen, so you can see how you’re doing. Below is example console output: Enter the mass of the skydiver (kg): 80 Enter the cross-sectional area of the skydiver (mˆ2): 1.035 Enter the drag coefficient of the skydiver: 0.581 Enter the ending time (sec): 16 Enter the time step (sec): 0.1 Enter the output filename: soln.csv Writing out file. Here are the first few lines: 0.100, 0.981 0.200, 1.9616 0.300, 2.9409 0.400, 3.9182 0.500, 4.8927 0.600, 5.8634 0.700, 6.8297 0.800, 7.7907 0.900, 8.7457 Enter another dive? (y/[n]): n For the case whose plot you turn in, you’ll want to calculate a substantial number of timesteps, out at least to t = 16 sec. Use a t = 0:1 sec, a mass of 80 kg, cross-sectional area of 1.035 m2, and a drag coefficient of 0.581 (drag coefficient is unitless).3 Your initial velocity, i.e., v(t = 0 sec), should be 0 m/s. By the way, using these settings, your graph should show the skydiver achieves terminal velocity; at a certain time, the velocity shown on the graph should level off. If you aren’t getting this behavior (or the sample output given above), something’s wrong. I expect you to make appropriate choices about variable types and which variables are class variables and which are local to a method. The private data (attributes) of any class should only be the data directly associated with being that kind of object. Thus, the private attributes of Skydiver should only be the data associated with being a skydiver. Any other variables that help in performing the tasks (i.e., the methods) should be local (i.e., defined within the method). Also, don’t forget to write accessor, mutator, and constructor methods, as appropriate. Finally, there should be at least one method that you write that can be used to provide output for tracing variables: The method should be called test-something, e.g., testStatistics. Somewhere in your program, there should be a call to that method. In the code you submit, that call should be commented out, but I should be able to find it.
This is what i currently have:
import java.util.Scanner;
public class array
{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
while(true){
System.out.println(\"Enter the mass of the skydiver (kg): \");
double mass=input.nextDouble();
System.out.println(\"Enter the cross-sectional area of the skydiver (mˆ2): \");
double crossSecArea=input.nextDouble();
System.out.println(\"Enter the drag coefficient of the skydiver: \");
double dragCoeff=input.nextDouble();
System.out.println(\"Enter the ending time (sec): \");
int endTime=input.nextInt();
System.out.println(\"Enter the time step (sec): \");
int timeStep=input.nextInt();
System.out.println(\"Enter the output filename: \");
int filename=input.nextInt();
System.out.println(\"Enter another dive? (y/[n]):\");
int drive=input.nextInt();
}
}
}
Solution
TerminalVelocity.java
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Scanner;
public class TerminalVelocity {
/*
* Sample function to return the velocity at point t.
* As you haven\'t provided the formula to calculate velocity at time t,
* i am calculating it as g*t (gravity * time) .
* Please change it to appropriate value and you will get the results.
*/
public static double calculateVelocity(double mass, double crossSecArea,double dragCoeff, double time, double span, double velocityEarlier) {
// v(t) = v(t-t)+(g- ((dragCoefficient*crossSectionArea*airDensity)/(2*mass))*v(t-t)*(t-t))t
return velocityEarlier + (9.81 - ((dragCoeff*crossSecArea*1.14)/(2*mass)) * velocityEarlier * (time - span)) * span;
}
public static void main(String a[]) {
Scanner input = new Scanner(System.in);
int drive = \'y\';
PrintWriter consoleWriter = new PrintWriter(System.out);
// keep looping till choice is y
while (drive == \'y\' || drive == \'Y\') {
// capture input values
System.out.println(\"Enter the mass of the skydiver (kg): \");
double mass = input.nextDouble();
System.out.println(\"Enter the cross-sectional area of the skydiver (mˆ2): \");
double crossSecArea = input.nextDouble();
System.out.println(\"Enter the drag coefficient of the skydiver: \");
double dragCoeff = input.nextDouble();
System.out.println(\"Enter the ending time (sec): \");
double endTime = input.nextDouble();
System.out.println(\"Enter the time step (sec): \");
double timeStep = input.nextDouble();
input.nextLine(); // Consume newline left-over
System.out.println(\"Enter the output filename: \");
String filename = input.nextLine();
System.out.println(\"Enter another dive? (y/[n]):\");
drive = input.next().charAt(0);
// determine size of required arrays
int size = (int)(endTime/timeStep) + 1;
// creating the appropriate size arrays
double velocity[] = new double[size];
double time[] = new double[size];
time[0] = 0.0;
velocity[0] = 0.0;
int i=1;
// calculate velocity at time t for each of the time durations
for(double t=timeStep; t < endTime; t+= timeStep) {
time[i] = t;
velocity[i] = calculateVelocity(mass, crossSecArea, dragCoeff, t, timeStep, velocity[i-1]);
i++;
}
// write the results to console and file
BufferedWriter fileWriter;
try {
fileWriter = new BufferedWriter(new FileWriter(filename));
printDetails(velocity, time, fileWriter); // writing to output file
printDetails(velocity, time, consoleWriter); // writing to console.. you can comment it if you want as mentioned in the question
fileWriter.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
// close the resources
input.close();
consoleWriter.close();
}
// function to print the details
public static void printDetails(double velocity[], double time[], Writer writer) throws IOException {
int size = (velocity.length > time.length) ? time.length : velocity.length;
writer.append(\"Velocity\\tTime\ \");
for(int i=0; i<size; i++) {
writer.append(String.format(\"%.4f\", velocity[i]) + \"\\t\");
writer.append(String.format(\"%.2f\", time[i]) + \"\ \");
}
}
}
Sample Output(IN file soln.csv):
Velocity Time
0.0000 0.00
0.9810 0.10
1.9620 0.20
2.9428 0.30
3.9234 0.40
4.9037 0.50
5.8837 0.60
6.8632 0.70
7.8421 0.80
8.8204 0.90
9.7980 1.00
10.7748 1.10
11.7508 1.20
12.7257 1.30
13.6996 1.40
14.6724 1.50
15.6440 1.60
16.6143 1.70
17.5832 1.80
18.5506 1.90
19.5165 2.00
20.4808 2.10
21.4433 2.20
22.4041 2.30
23.3630 2.40
24.3200 2.50
25.2750 2.60
26.2278 2.70
27.1785 2.80
28.1269 2.90
29.0729 3.00
30.0166 3.10
30.9577 3.20
31.8962 3.30
32.8321 3.40
33.7653 3.50
34.6957 3.60
In case you find some difficulty in changing the formula in the function, do let me know with formula. I will change the required code for you.
Thanks



