Something is wrong with my calculations I am suppose to calc
Something is wrong with my calculations. I am suppose to calculate the height by using these equations
currently my code is
/**
* Lab4.java
* Feburary 20,2017
* Maximiliano Bojorquez
*
* projectile problem
*/
import java.text.*;
import java.io.*;
import java.util.StringTokenizer;
public class Lab4 {
public static void main(String argv[]) throws IOException {
BufferedReader stdin =
new BufferedReader(new InputStreamReader (System.in));
String str = stdin.readLine();
DecimalFormat decf = new DecimalFormat(\"0.000\");
StringTokenizer tokenizer = new StringTokenizer(str);
str = tokenizer.nextToken();
double v1 = Double.parseDouble (str);
str = tokenizer.nextToken();
double v2 = Double.parseDouble (str);
str = tokenizer.nextToken();
double v3 = Double.parseDouble (str);
str = tokenizer.nextToken();
double v4 = Double.parseDouble (str);
double v5 = Double.parseDouble (str);
// projectile velocity
double Vel = v1;
System.out.println(\"The projectile\'s velocity is \" + decf.format(Vel) + \" feet per second\");
// angle of elevation
double Ang = v2;
System.out.println(\"The angle of elevation is \" + decf.format(Ang) + \" degrees\");
// distance from target
double dis = v3;
System.out.println(\"The distance to the target \" + decf.format(dis) + \" feet\");
// changeing degree to radians
double cosrad = Math.cos(Ang * (Math.PI/180));
double sinrad = Math.sin(Ang * (Math.PI/180));
// equation for time
double time = (dis)/(Vel * cosrad);
// Use the equation of time (above) to find the height of the target
double force = 32.17;
double height = (Vel * time * sinrad)-((force * time *time)/2);
System.out.println(\"The target\'s size is \" + decf.format(height) + \" feet\");
}
}
what i am getting is
The projectile\'s velocity is 2.000 feet per second
The angle of elevation is 10.000 degrees
The distance to the target 55.600 feet
The target\'s size is -12807.826 feet
when its supposed to be
Solution
import java.text.*;
import java.io.*;
import java.util.*;
import java.lang.*;
public class Lab4 {
public static void main(String args[]) throws IOException {
try{
Scanner sc = new Scanner(System.in);
DecimalFormat decf = new DecimalFormat(\"0.000\");
System.out.println(\"enter the values\");
int v1 = sc.nextInt();
double v2 = sc.nextDouble();
double v3 =sc.nextDouble();
double v4 = sc.nextDouble();
double v5 = sc.nextDouble();
// projectile velocity
double Vel = v1;
System.out.println(\"The projectile\'s velocity is \" + decf.format(Vel) + \" feet per second\");
// angle of elevation
double Ang = v2;
System.out.println(\"The angle of elevation is \" + decf.format(Ang) + \" degrees\");
// distance from target
double dis = v3;
System.out.println(\"The distance to the target \" + decf.format(dis) + \" feet\");
// changeing degree to radians
double cosrad =Math.cos( Math.toRadians(Ang));
double sinrad =Math.sin( Math.toRadians(Ang));
// equation for time
double time = (dis)/(Vel * cosrad*206265); // converted radians to seconds
// Use the equation of time (above) to find the height of the target
double force = 32.15;
double height = (Vel * time * sinrad*206265)/2-((force * time *time)/2);
System.out.println(\"The target\'s size is \" + decf.format(height) + \" feet\");
}
catch(Exception e){
System.out.println(\"exception\"+e);
}
}
}


