General

Chat

Anyone good at Java? I need some help

In physics, a common useful equation for finding the position s of a body in linear motion at a
given time t, based on its initial position s0, initial velocity v0, and rate of acceleration a is the
following:

Write code to declare variables for s0, v0, a, and t, and then write the code to compute s based
on these values.

September 12, 2014

2 Comments • Newest first

iDrinkOJ

public class D{
double s0, v0, a, time;

public D(double s0, double v0, double a, double time){
this.s0=s0; this.v0=v0; this.a=a; this.time=time;
} public double getTheD()
{ return s0+v0*time+ .5*a*time*time;
} public static void main(String[] args)
{ double s0=.8, v0=7.6, a=-9.8, time=.77;
//change values

D D = new D(s0, v0, a, time);
System.out.printf("s1 = %f", D.getTheD());

}
} //source: barely pass physics, can't code
//c version
#include <stdio.h>
int main()
{ double s0, v0, a, time;
scanf("%lf %lf %lf %lf", &s0, &v0, &a, &time);
printf("%lf", (s0+v0*time+ .5*a*time*time));
return 0;
}

Reply September 12, 2014 - edited
fun2killu

what's the equation?

also are you using a book to learn java?

Reply September 12, 2014 - edited