Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 shoot (double alpha, double v, double deltaSec) { ArrayList points = new ArrayList(); xVel = v * Math.cos(Math.toRadians(alpha)); yVel = v * Math.sin(Math.toRadians(alpha)); points.add(getLocation()); move(deltaSec); points.add(getLocation()); while (yPos > 0) { move(deltaSec); points.add(getLocation()); } return points; } }

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions

Question

Solve the proportion. 6 X || 3 2

Answered: 1 week ago