QUESTION 2: Create a class distance and a function double Distanc() with three parameters in and acc all of double types. Find and return the value of d from the following relation d = ut + 1/2 at2 Write a main function to input velocity (v), time (t) and acceleration (a) and by invoking funct Distanco print the value of d, v, t and a. The program should be properly documented . Solve out the program.
Answers
Answer:
I cannot dt this answer because I cannot understand the question
Answer:
Here u go:
import java.util.*;
public class distance
{
double distance(double u, double time, double acc)
{
double d;
d = (u*time) + ((1/2)*acc*(time*time));
return d;
}
void main()
{
Scanner sc = new Scanner(System.in);
double v,t,a,result;
System.out.println("Enter the following data");
System.out.print("Enter velocity(v)=");
v=sc.nextDouble();
System.out.print("Enter time(t)= ");
t= sc.nextDouble();
System.out.print("Enter acceleration (a)= ");
a= sc.nextDouble();
result= (distance(v,t,a));
System.out.println("The results are: ");
System.out.println("velocity (v)= "+v);
System.out.println("Time (t)= "+t);
System.out.println("Acceleration (a)= "+a);
System.out.println("Final result (d)= "+result);
}
}
Explanation: