让我说我有一个班级。
如何使用加速方法的结果并将其置于时间方法中?
package MyPackage;
import java.util.Scanner;
public class MPMethod {
Scanner input = new Scanner(System.in);
double distance = 0.0;
double time = 0.0;
double acceleration = 0.0;
double initialVelocity = 0.0;
double finalVelocity = 0.0;
public double accel()
{
System.out.println("enter acceleration: ");
acceleration = input.nextDouble();
return acceleration;
}
public double time()
{
System.out.println("enter time: ");
time = input.nextDouble();
return time;
}
public double dist()
{
System.out.println("enter distance: ");
distance = input.nextDouble();
return distance;
}
public double acceleration(double distance, double time) // how can i use the result of this method and put it inside the time method?
{
double result = distance / ((initialVelocity * time)+ 0.5 *(time*time));
return result;
}
public double time (double accel, double dist)
{
double result = acceleration()*accel *dist;
return result;
}
}
答案 0 :(得分:0)
您可以执行以下操作
double accResult=new MPMethod().acceleration(2,5);// will assign
the returning value to acResult
现在
new MPMethod().time(accResult,2);