ODD TUNINGS

Physics is Hard

While teaching myself JAVA in highschool, I spent a bit of time writing a projectile velocity calculator.

Now, it’s been a while since I’ve coded. I don’t know how coherent the code is or how well it works. But here is the code and a zipped JAVA program if anyone wants to pick through it.

physics is hard ext

PhysicsIsHard.java

package physics.is.hard;
import java.util.Scanner;

public class PhysicsIsHard {
public static Scanner userInput = new Scanner(System.in);
public static void dispOut (String texthere){
System.out.println(texthere);
}
public static void insVB (){
dispOut (“insVA=”);
double insVA = userInput.nextDouble();
dispOut (“Acc=”);
double acc = userInput.nextDouble();
dispOut (“timeAB=”);
double timeAB = userInput.nextDouble();
Point pA;
pA = new Point();
pA.insV = insVA;
Point pB;
pB = new Point();
pB.insV = (insVA+ acc*timeAB);
dispOut (“Final velocity =” + pB.insV);
}
public static void insVB2 (){
dispOut (“insVA=”);
double insVA = userInput.nextDouble();
dispOut (“Acc=”);
double acc = userInput.nextDouble();
dispOut (“timeAB=”);
double timeAB = userInput.nextDouble();
Point pA;
pA = new Point();
pA.insV = insVA;
Point pB;
pB = new Point();
pB.insV = (insVA+ acc*timeAB);
dispOut (“Final velocity =” + (pB.insV*pB.insV));

}
public static void insVA_accDisp(){
Point pA = new Point();
Point pB = new Point();
dispOut (“xLocA=”);
pA.Loc.xL = userInput.nextDouble();
dispOut (“xLocB=”);
pB.Loc.xL = userInput.nextDouble();
dispOut (“acc=”);
double acc = userInput.nextDouble();
dispOut (“insVB=”);
pB.insV = userInput.nextDouble();

dispOut (“Initial Velocity =” + Math.sqrt((pB.insV*pB.insV)-(2*acc)*(pB.Loc.xL-pA.Loc.xL)));
}
public static void dis_acc (){
dispOut (“xLocA=”);
double xLocA = userInput.nextDouble();
dispOut (“insVA=”);
double insVA = userInput.nextDouble();
dispOut (“Acc=”);
double acc = userInput.nextDouble();
dispOut (“timeAB=”);
double timeAB = userInput.nextDouble();
Point pA;
pA = new Point();
pA.Loc.xL = xLocA;
pA.insV = insVA;
Point pB;
pB = new Point();
pB.Loc.xL = (xLocA + (insVA*timeAB) + .5*acc*(timeAB*timeAB));
pB.insV = (insVA+ acc*timeAB);
dispOut (“Displacement AB =” + (pB.Loc.xL));
}
public static void dis_insVB (){
Point pA = new Point();
Point pB = new Point();
dispOut (“xLocA=”);
double xLocA = userInput.nextDouble();
dispOut (“insVA=”);
double insVA = userInput.nextDouble();
dispOut (“Acc=”);
double acc = userInput.nextDouble();
dispOut (“insVB=”);
double insVB = userInput.nextDouble();
pA.Loc.xL = xLocA;
pA.insV = insVA;
pB.insV = insVB;
dispOut (“Displacement AB =” + ((pB.insV*pB.insV)/((pA.insV*pA.insV)+2*acc))+pA.Loc.xL);
}
public static void dis_Vel() {
dispOut (“xLocA=”);
double xLocA = userInput.nextDouble();
dispOut (“avgVel=”);
double avgVel = userInput.nextDouble();
dispOut (“timeAB=”);
double timeAB = userInput.nextDouble();
Point pA;
pA = new Point();
pA.Loc.xL = xLocA;

dispOut (“Displacement AB = ” + (xLocA + (avgVel*timeAB)));
}
public static void aV_AB (){

dispOut (“InsVB=”);
double insVB = userInput.nextDouble();

dispOut (“InsVA=”);
double insVA = userInput.nextDouble();

dispOut (“Average Velcity =” + (insVA + insVB)/2);
}
public static void acc_timeABdisp(){
Point pA = new Point();
Point pB = new Point();
dispOut (“insVA=”);
pA.insV = userInput.nextDouble();
dispOut (“dispAB=”);
double dispAB = userInput.nextDouble();
dispOut (“timeAB=”);
double timeAB = userInput.nextDouble();

dispOut (“Acceleration =” + dispAB/(.5*(timeAB*timeAB)));
}
public static void acc_dispVels(){
Point pA = new Point();
Point pB = new Point();
dispOut (“insVA=”);
pA.insV = userInput.nextDouble();
dispOut (“insVB=”);
pB.insV = userInput.nextDouble();
dispOut (“dispAB=”);
double ABdisp = userInput.nextDouble();

dispOut (“Acceleration =” + (((pB.insV*pB.insV)-(pA.insV*pA.insV))/(2*ABdisp)));
}
public static void acc_timeVels(){
Point pA = new Point();
Point pB = new Point();
dispOut (“insVA=”);
pA.insV = userInput.nextDouble();
dispOut (“insVB=”);
pB.insV = userInput.nextDouble();
dispOut (“timeAB=”);
double timeAB = userInput.nextDouble();

dispOut (“Acceleration =” + ((pB.insV-pA.insV)/timeAB));

}
public static void time_dispAcc(){
Point pA = new Point();
Point pB = new Point();
dispOut (“insVA=”);
pA.insV = userInput.nextDouble();
dispOut (“dispAB=”);
double dispAB = userInput.nextDouble();
dispOut(“acc=”);
double acc = userInput.nextDouble();
dispOut (“Time =” + Math.sqrt(dispAB/(.5*acc)));
}
public static void displayVariables(vector v){
dispOut (“”);
}
public static void lProj_magAngle(String airR){
Point pA = new Point();
Point pB = new Point();
dispOut(“pA.insV:”);
pA.insV = userInput.nextDouble();
dispOut(“pA.angle:”);
pA.dir.angleD_x = userInput.nextDouble();
/*
dispOut(“pA.dia:”);
pA.dia = userInput.nextDouble();
dispOut(“height:”);
double height = userInput.nextDouble();
pA.Loc.xL = 0;
pA.Loc.yL = height;
*/
Path launch = new Path();
launch.send.init(pA);

launch.tAirtime = 2*(launch.send.velY/9.81);

System.out.println(“AirTime= ” +launch.tAirtime);
System.out.println(“VertVel= ” + launch.send.velY);
System.out.println(“HorVel= ” + launch.send.velX);

launch.recieve.fin(launch.send);

dispOut (“send”);
dispOut (“(“+pA.Loc.xL+”,”+pA.Loc.yL+”) ” + launch.send.direction.angleD_x + “deg ” + launch.send.scalarMag + “m/s”);
dispOut (“Range :” + launch.send.velX*(launch.tAirtime));

}
public static void sphereDrag(double diameter, double velocity){
double f_Drag = (.25*1.255*(.25*Math.PI*(diameter*diameter))*velocity)*(-1);
}
public double grav = -9.81;
public double airD = 1.255;

public static void main(String[] args) {
String equationTarget;
do {
dispOut (“Find? N=Exit (iV = point velocity || aV = average velocity || a = acceleration || d = displacement || t = time”);
equationTarget = userInput.nextLine();

switch (equationTarget) {
case “d at” : dis_acc();
break;
case “d avt” : dis_Vel();
break;
case “d fva” : dis_insVB();
break;
case “iva ad” : insVA_accDisp();
break;
case “ivb at” : insVB2();
break;
case “launch” : lProj_magAngle(“n”);
break;
case “launchAD” : lProj_magAngle(“y”);
break;
}

if (“d”.equalsIgnoreCase(equationTarget)){
dispOut(“Given? (a = acceleration || v = average velocity || fv = point velocity B”);
String subTargetD = userInput.nextLine();
if (“a”.equalsIgnoreCase(subTargetD)){
dis_acc();
}
if (“v”.equalsIgnoreCase(subTargetD)){
dis_Vel();
}
if (“fv”.equalsIgnoreCase(subTargetD)){
dis_insVB();
}
}
if (“iV”.equalsIgnoreCase(equationTarget)){
dispOut (“Of? (i = initial Velocity || f = final velocity)”);
String subTarget_iV = userInput.next();
if (“i”.equals(subTarget_iV)){
insVA_accDisp();
}
if (“f”.equalsIgnoreCase(subTarget_iV)){
insVB();
}
}

if (“aV”.equalsIgnoreCase(equationTarget)){
aV_AB();
}

if (“a”.equalsIgnoreCase(equationTarget)){
dispOut (“Given? ( tV = time and velocity || dV = displacement and velocity A,B || dT = displacement and time”);
String subTargetA = userInput.next();

if (“dT”.equalsIgnoreCase(subTargetA)){
acc_timeABdisp();
}
if (“tV”.equalsIgnoreCase(subTargetA)){
acc_timeVels();
}
if (“dV”.equalsIgnoreCase(subTargetA)){
acc_dispVels();
}
}
if (“t”.equalsIgnoreCase(equationTarget)){
//dispOut (“Given? “);
//String subTargetT = userInput.next();
time_dispAcc();
}
} while (!”N”.equalsIgnoreCase(equationTarget));
}
}