This Java program should be called Cannonball. it is about to draw the trajectory of the cannonball . In this program , you neet do design a class Cannonball which model a cannonball that is fired...

This Java program should be called Cannonball. it is about to draw the trajectory of the cannonball . In this program , you neet do design a class Cannonball which model a cannonball that is fired into the air. A ball has • x and y position. • x and y velocity. to supply the following methods in the Cannonball class: • supply a constructor with an x-position (the y-position is initially 0). • A method move(double deltaSec) that moves the ball to the next position. First compute the distance traveled in deltaSec seconds, using the current velocities, then update the x- and y-positions; then update the y-velocity by taking into account the gravitational acceleration of –9.81 m/s2; the x-velocity is unchanged. • A method Point getLocation() that gets the current location of the cannonball, rounded to integer coordinates. • A method ArrayList shoot(double alpha, double v, double deltaSec) whose arguments are the angle a and initial velocity v. (Compute the x-velocity as v cos a and the y-velocity as v sin a; then keep calling move with the given time interval until the y-position is 0; return an array list of locations after each call to move.) and use this class in a program that prompts the user for the starting angle(alpha) and the initial velocity(V). Then use shoot function and draw the trajectory of the cannonball . below will be a good template as a hint to start. //hint... public class Cannonball { double xPos ; double yPos ; double xVel ; double yVel ; //A constructor with an x-position (the y-position is initially 0). public Cannonball( double xPos){ this . xPos = xPos; yPos = 0; } public void move( double deltaSec){ //... } //return a point representing current x and y position public Point getLocation(){ //... } /* set velocity based upon angle (alpha) and launch speed (v), move ball and record points until ball reaches the ground, return list. */ public ArrayList shoot( double alpha, double v, double deltaSec){ //... } public static void main(String[] args) { //Todo auto-generate method. Cannonball b1 = new Cannonball(10); ArrayList path = b1.shoot(Math. PI /4, 100 ,1); JFrame frame = new JFrame(); frame.setSize(500,500); JComponent component = new JComponent() { public void paintComponent (Graphics g){ for ( int i = 0 ;i g.drawLine(path.get(i). x , path.get(i). y , path.get(i+1). x , path.get(i+1). y ); } } }; frame.add(component); frame.setVisible( true ); } }
Nov 14, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here