Question
I was given instructions to use the draw method to visually show a cannonball being fired into the air here is the code for the
I was given instructions to use the draw method to visually show a cannonball being fired into the air here is the code for the mathematical representation
import java.awt.*; import java.util.ArrayList;
public class Cannonball { // instance variables of Cannonball private double xPos; private double yPos; private double xVel; private double yVel;
/** * Constructor for Cannonball */ public Cannonball(double xPos) { // initialise instance variables this.xPos = xPos; yPos = 0; xVel = 0; yVel = 0; }
/** * move(double deltaSec) moves the ball to the next position. */ public void move(double deltaSec) { double xDistTraveled = xVel * deltaSec; double yDistTraveled = yVel * deltaSec + (1/2) * -9.81 * deltaSec * deltaSec; xPos = xPos + xDistTraveled; yPos = yPos + yDistTraveled; yVel = yVel + -9.81 * deltaSec; }
/** * The getLocation() gets the current location of the cannonball */ public Point getLocation() { Point point = new Point((int) xPos, (int) yPos); return point; }
/** * shoot method for the cannon ball. */ public ArrayList
But I am having trouble getting the visual drawn, also I get an error when I try to run this
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started