Scientific Programming II

ModSim

Applets Quiz


Problem 1 (10 Points)

Using the class Particle given below, write an applet that will show the particle in actual freefall. You should include the following instance variables:

You should also include implementations for the following methods:

You only are required to have three import statements (others shouldn't be necessary)

The applet should update the screen every ~100ms for a smoother animation, but other update values are fine. Make sure when you copy-and-paste that the package is correct (Netbeans should yell at you if not, see image below code).

package edu.govschool;

public class Particle 
{
    // We don't want static in case we have multiple
    // displayed particles, so we can have them fall
    // at different times.
    private double time;
    // Gravity, however, is THE LAW
    private static final double GRAVITY = 9.81;
    
    /**
     * Default constructor.
     * Creates a new <code>Particle</code> with the
     * time set to 0.
     */
    public Particle()
    {
        this.time = 0;
    }
    
    /**
     * Gets the current y-coordinate of the <code>Particle</code>.
     * @return the current y-coordinate
     */
    public int getY()
    {
        return (int) (0.5 * GRAVITY * Math.pow(time, 2));
    }
    
    /**
     * Sets the time.
     * @param time the time to set
     */
    public void setTime(int time)
    {
        this.time = time;
    }
}

Netbeans yelling