Equations of Motion Revisited with Methods (20 points) u at 2. s ut at 3. v u as
ID: 3677841 • Letter: E
Question
Equations of Motion Revisited with Methods (20 points) u at 2. s ut at 3. v u as Redo the question from Assignment 1 by using methods. Your program must have three methods for olving each of the three equations respectively solveEanl method receives the u, a and t as arguments, and returns value v. solve Eqn2 method receives the u, a and t as arguments, and returns value s solveEqn3 method receives the u, a and s as arguments, and returns value of v2. Note: Be careful with data type of arguments and the return type of methods.Explanation / Answer
import java.text.DecimalFormat;
public class Motion {
public static double solveEqn1(double u, double a, double t){
return u + a*t;
}
public static double solveEqn2(double u, double a, double t){
return u*t + (0.5*a*t*t);
}
public static double solveEqn3(double u, double a, double s){
return u*u + 2*a*s;
}
public static void main(String[] args) {
// to format double value upto 2 decimal point
DecimalFormat df = new DecimalFormat("#.00");
double u = 12.5;
double t = 2.5;
double a = 3.4;
double v = solveEqn1(u, a, t);
double s = solveEqn2(u, a, t);
double vsq = solveEqn3(u, a, s);
System.out.println("Value of v: "+df.format(v));
System.out.println("Value of s: "+df.format(s));
System.out.println("Value of v square : "+df.format(vsq));
}
}
/*
Output:
Value of v: 21.00
Value of s: 41.88
Value of v square : 441.00
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.