Hey everyone so I am having the damndest time trying to find out why when I print out the string from the simulate flight method that it only prints out one line and doesn't go until height reaches 0.
import java.text.*; public class cannonball { private double v; private double t; final double G = 9.81; private double h; private double h1; private double maxHeight; private String abc; private String str; public cannonball(double Velocity) { v = Velocity; h = 0; h1=0; t=0; } public String simulateFlight() { DecimalFormat fmt = new DecimalFormat("#.####"); t=t+1 ; h = (v*t)-(0.5*G*Math.pow(t,2)); v = v - G*t; h1 = v*t; while(h <= 0) { t=t+1; h = (v*t)-(0.5*G*Math.pow(t,2)); v = v - G*t; h1 = v*t; str =(fmt.format(t)+"\t\t"+fmt.format(v)+"\t\t"+fmt.format(h1)+"\t\t"+fmt.format(h)); } return str; } public double getMaxHeight() { t=t+0.01; h = (v*t)-0.5*G*Math.pow(t,2); h1 = v*t; while(h <= 0) { t=t+0.01; h = (v*t)-0.5*G*Math.pow(t,2); h1 = v*t; v = v - G*t; if(h>h1) maxHeight = h; if(h1>h) maxHeight = h1; } return maxHeight; } public String send() { String abc = "The maximum height is: " + maxHeight; return abc; } public String toString() { DecimalFormat fmt = new DecimalFormat("#.##"); return(fmt.format(t)+"\t\t"+fmt.format(v)+"\t\t"+fmt.format(h1)+"\t\t"+fmt.format(h)); } }