Java 更新实例方法问题

Java 更新实例方法问题,java,Java,在updateField方法中,无法将currentTime更新1秒,这将触发currentVelocity和currentPosition公式。所有这些都通过跟踪方法进行协作 任何帮助都将不胜感激。(旁注,我一个月前才开始学习如何用java编程,所以不要对我太苛刻。) 公共类FallingItem{ 私人双初始位置=0; 私人双初始速度=0; 私有int currentTime=0; 专用双电流位置=0; 专用双电流速度=0; 公共静态最终双终端速度=-500; 公共下降项目(双初始速度、双初

updateField
方法中,无法将
currentTime
更新1秒,这将触发
currentVelocity
currentPosition
公式。所有这些都通过
跟踪方法进行协作

任何帮助都将不胜感激。(旁注,我一个月前才开始学习如何用java编程,所以不要对我太苛刻。)

公共类FallingItem{
私人双初始位置=0;
私人双初始速度=0;
私有int currentTime=0;
专用双电流位置=0;
专用双电流速度=0;
公共静态最终双终端速度=-500;
公共下降项目(双初始速度、双初始位置){
初始速度=初始速度;
currentVelocity=初始速度;
初始位置=初始位置;
当前位置=初始位置;
currentTime=0;
}
公共双getCurrentTime(){
返回时间;
}
公共双getCurrentPosition(){
返回当前位置;
}
公共void updateFields(){
currentTime++;
this.currentVelocity=-32*this.currentTime+初始速度;
if(此.currentVelocity<终端速度){
此.currentVelocity=终端速度;
} 
if(this.currentVelocity=终端速度){
System.out.println(“在“+this.currentTime+”秒时,位置为“+this.currentPosition
+“英尺和速度为”+this.currentVelocity+“英尺/秒”);
}    
}
}

经过一些修改:

package general;

public class DummyTesting {

private double INITIAL_POSITION = 0;
private double INITIAL_VELOCITY = 0;
private long currentTime = 0;
private double currentPosition = 0;
private double currentVelocity = 0;

public static final double TERMINAL_VELOCITY = -500;

public DummyTesting (double initialVelocity, double initialPosition){
    INITIAL_VELOCITY = initialVelocity; 
    currentVelocity = initialVelocity;
    INITIAL_POSITION = initialPosition;
    currentPosition = initialPosition;
    currentTime = 0;
}

public long getCurrentTime () {
    return System.currentTimeMillis() / 1000L;
}

public double getCurrentPosition () {
    return currentPosition;
}
public void updateFields () {
    currentTime = this.getCurrentTime() + 1;      
    this.currentVelocity = -32 * this.currentTime + INITIAL_VELOCITY;
    if (this.currentVelocity < TERMINAL_VELOCITY){
        this.currentVelocity = TERMINAL_VELOCITY;
    } 

    if (this.currentVelocity <= TERMINAL_VELOCITY){
        this.currentPosition = this.currentPosition - TERMINAL_VELOCITY;
    }
    else {
        this.currentPosition = -16 * Math.pow(this.currentTime, 2) + currentVelocity
        * this.currentTime + this.currentPosition;
    }
    System.out.println("System parameters: CurrentPosition:" + currentPosition + " Current Time:" + currentTime + " currentVelocity:" + currentVelocity);
}   

public void tracking () {
    System.out.println ("Object released at " + INITIAL_POSITION + " feet, at"
    + " an initial velocity of " + INITIAL_VELOCITY + " feet/sec.");

    while (this.currentVelocity >= TERMINAL_VELOCITY) {
        System.out.println ("At " + this.currentTime + " seconds, position is " + this.currentPosition
        + " feet and velocity is " + this.currentVelocity + " feet/sec");
    }    
}

public static void main(String[] args){
    DummyTesting dt = new DummyTesting(-70, 40);
    dt.updateFields();
}
package-general;
公共类测试{
私人双初始位置=0;
私人双初始速度=0;
专用长currentTime=0;
专用双电流位置=0;
专用双电流速度=0;
公共静态最终双终端速度=-500;
公共Dummy测试(双初始速度、双初始位置){
初始速度=初始速度;
currentVelocity=初始速度;
初始位置=初始位置;
当前位置=初始位置;
currentTime=0;
}
公共长getCurrentTime(){
返回系统.currentTimeMillis()/1000L;
}
公共双getCurrentPosition(){
返回当前位置;
}
公共void updateFields(){
currentTime=this.getCurrentTime()+1;
this.currentVelocity=-32*this.currentTime+初始速度;
if(此.currentVelocity<终端速度){
此.currentVelocity=终端速度;
} 
if(this.currentVelocity=终端速度){
System.out.println(“在“+this.currentTime+”秒时,位置为“+this.currentPosition
+“英尺和速度为”+this.currentVelocity+“英尺/秒”);
}    
}
公共静态void main(字符串[]args){
Dummy测试dt=新Dummy测试(-70,40);
dt.updateFields();
}
}

输出
系统参数:CurrentPosition:540.0当前时间:1455848058 currentVelocity:-500.0

经过一些修改:

package general;

public class DummyTesting {

private double INITIAL_POSITION = 0;
private double INITIAL_VELOCITY = 0;
private long currentTime = 0;
private double currentPosition = 0;
private double currentVelocity = 0;

public static final double TERMINAL_VELOCITY = -500;

public DummyTesting (double initialVelocity, double initialPosition){
    INITIAL_VELOCITY = initialVelocity; 
    currentVelocity = initialVelocity;
    INITIAL_POSITION = initialPosition;
    currentPosition = initialPosition;
    currentTime = 0;
}

public long getCurrentTime () {
    return System.currentTimeMillis() / 1000L;
}

public double getCurrentPosition () {
    return currentPosition;
}
public void updateFields () {
    currentTime = this.getCurrentTime() + 1;      
    this.currentVelocity = -32 * this.currentTime + INITIAL_VELOCITY;
    if (this.currentVelocity < TERMINAL_VELOCITY){
        this.currentVelocity = TERMINAL_VELOCITY;
    } 

    if (this.currentVelocity <= TERMINAL_VELOCITY){
        this.currentPosition = this.currentPosition - TERMINAL_VELOCITY;
    }
    else {
        this.currentPosition = -16 * Math.pow(this.currentTime, 2) + currentVelocity
        * this.currentTime + this.currentPosition;
    }
    System.out.println("System parameters: CurrentPosition:" + currentPosition + " Current Time:" + currentTime + " currentVelocity:" + currentVelocity);
}   

public void tracking () {
    System.out.println ("Object released at " + INITIAL_POSITION + " feet, at"
    + " an initial velocity of " + INITIAL_VELOCITY + " feet/sec.");

    while (this.currentVelocity >= TERMINAL_VELOCITY) {
        System.out.println ("At " + this.currentTime + " seconds, position is " + this.currentPosition
        + " feet and velocity is " + this.currentVelocity + " feet/sec");
    }    
}

public static void main(String[] args){
    DummyTesting dt = new DummyTesting(-70, 40);
    dt.updateFields();
}
package-general;
公共类测试{
私人双初始位置=0;
私人双初始速度=0;
专用长currentTime=0;
专用双电流位置=0;
专用双电流速度=0;
公共静态最终双终端速度=-500;
公共Dummy测试(双初始速度、双初始位置){
初始速度=初始速度;
currentVelocity=初始速度;
初始位置=初始位置;
当前位置=初始位置;
currentTime=0;
}
公共长getCurrentTime(){
返回系统.currentTimeMillis()/1000L;
}
公共双getCurrentPosition(){
返回当前位置;
}
公共void updateFields(){
currentTime=this.getCurrentTime()+1;
this.currentVelocity=-32*this.currentTime+初始速度;
if(此.currentVelocity<终端速度){
此.currentVelocity=终端速度;
} 
if(this.currentVelocity=终端速度){
System.out.println(“在“+this.currentTime+”秒时,位置为“+this.currentPosition
+“英尺和速度为”+this.currentVelocity+“英尺/秒”);
}    
}
公共静态void main(字符串[]args){
Dummy测试dt=新Dummy测试(-70,40);
dt.updateFields();
}
}

输出
系统参数:CurrentPosition:540.0当前时间:1455848058 currentVelocity:-500.0

在哪里调用updateFields?在哪里调用updateFields?