Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am having trouble contructinf this class, Any suggestions pleade 1. Define a J

ID: 3764754 • Letter: I

Question

I am having trouble contructinf this class, Any suggestions pleade

1. Define a Java class with properties and methods for a Falling Object,

The class will have the following private properties:

constant initial position

constant initial velocity

current time
current position

current velocity

define a public static constant within the class to hold the value of the terminal velocity (-500 feet/sec)

Because this constant will be declared static, it will be created only once (instead of once for each object). And because it will be declared public, it can be used by both classes.

Within the FallingObject class:
Define a constructor, with parameters that pass in the user entered initial position and initial velocity, and use them to:

o Initialize the current time to 0.

o Initialize both the initial position constant and the current position data field to the value of the parameter for the initial position.

o Initialize both the initial velocity constant and the current velocity data field to the value of the parameter for the initial velocity.

Define three instance methods (getters) to:

o Get and return the current time
o Get and return the current position o Get and return the current velocity

2. Define an instance method to display the current time, current position, and current velocity of the object (see format in Sample Output below).

o Position and velocity figures should be displayed to one decimal place.
Define an update instance method to reset the data field values for the falling object for the next second. Note that there will be no loops in this method. This method will:

o Increment the current time by 1.

o Calculate and set the current velocity of the object at the updated current time, using the formula from the Problem Summary.

Air resistance affects the acceleration of falling objects, so they will eventually reach a maximum terminal velocity. The terminal velocity of an object will vary, depending on the object's mass.
For this program we will not allow the velocity to ever pass the terminal velocity of -500 feet/second.
if the calculated velocity is less than the terminal velocity of -500 feet/second, the program should use -500 feet/second as the velocity instead the calculated value.
Use the terminal velocity constant from the FallingObject class in your code.

o Calculate and set the current position of the object at the updated current time.

If the object has reached the terminal velocity, the P(t) function from the Problem Summary cannot be used to calculate the position. Therefore, the program must check to see if terminal velocity was reached before calculating the position.

If terminal velocity has been reached, subtract 500 feet from the previous position (i.e. add the terminal velocity amount) to get the new position, instead of calculating the position via the formula.
Otherwise, use the position function to determine the current position of the object.
Position = P(t) = –16t2 + V0t + H0
Velocity =V(t) = –32t + V0

P(t) is the current position of the object at t seconds

V0 = initial velocity
H0 = initial height (position)

t = time in seconds

V(t) = current velocity of the object at after t seconds,
V0 = initial velocity of the object in feet/sec

Explanation / Answer

package current;

public class FallingObjectTest {

   public static void main(String[] args) {
       FallingObject fb = new FallingObject(100,10);
       fb.display();
       for(int i = 0; i < 20; i++) {
           fb.update();
           fb.display();
       }
      
   }
}

class FallingObject {
  
   public static final int TERMINAL_VELOCITY = -500;// feet/sec
   private float initialPosition;

   private float initialVelocity;

   private int currentTime;
   private float currentPosition;

   private float currentVelocity;
  
  
   public FallingObject(float initialPosition, float initialVelocity ) {
   /*o Initialize the current time to 0.

   o Initialize both the initial position constant and the current position data field to the value of the parameter for the initial position.
  
   o Initialize both the initial velocity constant and the current velocity data field to the value of the parameter for the initial velocity.
   */
       currentTime = 0;
       this.initialPosition = initialPosition;
       this.currentPosition = initialPosition;
       this.initialVelocity = initialVelocity;
       this.currentVelocity = initialVelocity;
   }

   //2. Define an instance method to display the current time, current position, and current velocity of the object (see format in Sample Output below).
   public void display() {
       System.out.println("current time : "+this.currentTime+" secs   current position : "+this.currentPosition+" current velocity : "+this.currentVelocity);
   }
  
   public void update() {
       /*o Increment the current time by 1.

          o Calculate and set the current velocity of the object at the updated current time, using the formula from the Problem Summary.
       */
      
       currentTime++;
       //Position = P(t) = –16t2 + V0t + H0
       //Velocity =V(t) = –32t + V0
       currentVelocity = -32 * currentTime + initialVelocity;
       if(currentVelocity < TERMINAL_VELOCITY)
           currentVelocity = TERMINAL_VELOCITY;
       //If terminal velocity has been reached, subtract 500 feet from the previous position (i.e. add the terminal velocity amount) to get the new position,
       if(currentVelocity == TERMINAL_VELOCITY)
           currentPosition += TERMINAL_VELOCITY;
       else
           currentPosition = -16 * (currentTime * currentTime)+ initialVelocity * currentTime + initialPosition;
   }
  
   public float getInitialPosition() {
       return initialPosition;
   }

   public float getInitialVelocity() {
       return initialVelocity;
   }

   public int getCurrentTime() {
       return currentTime;
   }

   public float getCurrentPosition() {
       return currentPosition;
   }

   public float getCurrentVelocity() {
       return currentVelocity;
   }
  
  
  
  
}

--------output-----------------

current time : 0 secs   current position : 100.0 current velocity : 10.0
current time : 1 secs   current position : 94.0 current velocity : -22.0
current time : 2 secs   current position : 56.0 current velocity : -54.0
current time : 3 secs   current position : -14.0 current velocity : -86.0
current time : 4 secs   current position : -116.0 current velocity : -118.0
current time : 5 secs   current position : -250.0 current velocity : -150.0
current time : 6 secs   current position : -416.0 current velocity : -182.0
current time : 7 secs   current position : -614.0 current velocity : -214.0
current time : 8 secs   current position : -844.0 current velocity : -246.0
current time : 9 secs   current position : -1106.0 current velocity : -278.0
current time : 10 secs   current position : -1400.0 current velocity : -310.0
current time : 11 secs   current position : -1726.0 current velocity : -342.0
current time : 12 secs   current position : -2084.0 current velocity : -374.0
current time : 13 secs   current position : -2474.0 current velocity : -406.0
current time : 14 secs   current position : -2896.0 current velocity : -438.0
current time : 15 secs   current position : -3350.0 current velocity : -470.0
current time : 16 secs   current position : -3850.0 current velocity : -500.0
current time : 17 secs   current position : -4350.0 current velocity : -500.0
current time : 18 secs   current position : -4850.0 current velocity : -500.0
current time : 19 secs   current position : -5350.0 current velocity : -500.0
current time : 20 secs   current position : -5850.0 current velocity : -500.0