SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Stuart Reges, Marty Stepp
Chapter:
Primitive Data And Definite Loops
Exercise:
Exercises
Question:1 | ISBN:9780136091813 | Edition: 2

Question

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 s_{0} , initial velocity v_{0}, and rate of acceleration a, is the following:

s = s_{0} + v_{0}t + \frac{1}{2}at^{2}

Write code to declare variables for s_{0}, v_{0}, a, and t, and then write the code to compute s on the basis of these values.

 

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Program:

public class Ch02Ex01
{
	public static void main(String[] args)
	{
		double s0;
		double v0;
		double a;
		double t;
		double s;
		
		s0 = 12.0;
		v0 = 3.5;
		a = 9.8;
		t = 10.0;
		
		s = s0 + (v0 * t) + (0.5 * a * t * t);
		
		System.out.println("Initial position s0: " + s0);
		System.out.println("Initial velocity v0: " + v0);
		System.out.println("Given time t: " + t);
		System.out.println("Rate of acceleration a: " + a);
		System.out.println("Position s if a body in linear motion: " + s);
	}
}

Output:

Initial position s0: 12.0
Initial velocity v0: 3.5
Given time t: 10.0
Rate of acceleration a: 9.8
Position s if a body in linear motion: 537.0
0 0

Discussions

Post the discussion to improve the above solution.