This problem is for Introduction to Java Class 1 Implement a
This problem is for Introduction to Java Class:
1. Implement a class CannonBall Design class Cannonball to model a cannonball fired into the air. A ball has weight and coordinates xPosition and yPosition, and speed xVelocity and yVelocity
2. Supply the following member functions Constructor with weight and xPosition as parameters (yPosition is initially zero) Member status() displays the current status of the cannonball.
Member move(double sec) that moves the ball to the next position
First compute xDistanceMoved and yDistanceMoved in sec seconds, using current xVelocity and yVelocity values, e.g., xDistanceMoved = xVelocity *sec; then update the x and y positions, then update yVelocity by taking into account the gravitational acceleration of –9.81 m/sec2 : yVelocity = yVelocity -9.812 * sec; xVelocity remains unchanged.
A member function shoot() whose parameters are the angle angle and initial velocity v
a. compute the xVelocity as: v * Math.cos(angle) ex 1: v = 100 m/sec angle = 45 degrees So, xVelocity would be 70.71.
b. compute the yVelocity as: v * Math.sin(angle) ex 2: v = 100 m/sec angle = 70 degrees So, yVelocity would be 93.97.
c. LOOP to keep calling move() with a time interval of 0.1 seconds until the yPosition is 0 [i.e., until the ball hits the ground]
d. …call status() after every move().
e. Add a driver public static void main() method. Create a Cannonball object with appropriate parameter values for the starting angle and the initial velocity. [ just “hardwire” values in test code]
f. call the shoot() method. E.g.: myCannobBall.shoot(60, 70);
Solution
Your main class should be called CannonballViewer.
Complete the following classes in your solution:
Use the following class in your solution:
Use the following class as your tester class:
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);
 }
 }
 }


