Complete the following files:

Cannonball.java

/** This class simulates a cannonball fired at an angle. */ public class Cannonball { // private implementation . . . /** Constructs a Cannonball @param ivel the initial velocity of the ball @param angle the angle at which the cannonball was launched (in degrees) */ public Cannonball(double ivel, double angle) { . . . } /** Updates the position and velocity of this cannon ball after a given time interval. @param deltaT the time interval */ public void move(double deltaT) { . . . } /** Gets the x position of this cannon ball. @return the horizontal position */ public double getX() { . . . } /** Gets the y position of this cannon ball. @return the vertical position */ public double getY() { . . . } }

CannonballComponent.java

import javax.swing.JComponent; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; /** Draws the trajectory of a cannonball. */ public class CannonballComponent extends JComponent { private double initialVelocity; private double angle; /** Constructs a component that paints the flight of a cannonball @param ivel the initial velocity of the ball @param ang the angle at which the cannonball was launched */ public CannonballComponent(double ivel, double ang) { . . . } public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; while(ball.getY() >= 0) { ball.move(DELTA_T); . . . g2.draw(circle); } } }

CannonballViewer.java

Use the following files:

CannonballSnap.java

import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
   This is a driver for taking a screen snapshot 
   of the CannonballComponent class.
*/
public class CannonballSnap
{
   public static void main(String[] args)
   {
      JFrame frame = new JFrame();

      final int FRAME_WIDTH = 300;
      final int FRAME_HEIGHT = 300;

      frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
      frame.setTitle("CannonballViewer");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      double ivel = 50;

      double ang = 45;

      CannonballComponent component = new CannonballComponent(ivel, ang);
      frame.add(component);

      frame.setVisible(true);
   }
}

CannonballTester.java

public class CannonballTester
{
   public static void main(String[] args)
   {
      Cannonball ball = new Cannonball(100, 45); // 100 m/sec
      ball.move(1); // move by one second

      double x = ball.getX();
      System.out.println(x);
      System.out.println("Expected: " + (100 * Math.sqrt(2) / 2));
      double y = ball.getY();
      System.out.println(y);
      System.out.println("Expected: " + (100 * Math.sqrt(2) / 2));

      ball.move(1); // move by one second

      x = ball.getX();
      System.out.println(x);
      System.out.println("Expected: " + (200 * Math.sqrt(2) / 2));
      y = ball.getY();
      System.out.println(y);
      System.out.println("Expected: " + (200 * Math.sqrt(2) / 2 - 9.81));
   }
}