The problem states to write a method named fallingDistance that accepts an object's falling time as an argument. The method should return the distance that the object has fallen during the time interval. Demonstrate the method by calling it in a loop that passes the values 1-10 as arguments and displays the return value......
I got it to compile but get a hole bunch of this:
Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double
at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:3992)
at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2708)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2660)
at java.util.Formatter.format(Formatter.java:2432)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at fallingDistances1.fallingDistance(fallingDistances1.java:37)
at fallingDistances1.main(fallingDistances1.java:17)
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Help what am i doing wrong?
import java.util.*;
import java.io.*;
import java.text.DecimalFormat;
public class fallingDistances1
{
public static void main (String [] args) throws IOException
{
System.out.println("Time\tDistance");
System.out.println("-----------------");
fallingDistance();
}
// method
public static void fallingDistance ()
{
//constants
final double starting_time = 1.0;
final double max_time = 10.0;
final double increment = 1.0;
// variables
double distance;
double g = 9.8;
double t = 0;
double a = 0.5;
for (distance = starting_time; distance <= max_time; distance =+ increment)
{
//calculate distance
distance = (a)*(g)*(t*t);
System.out.printf("%d\t\t%.1f\n",t, distance);
System.exit(0);
}
}
}