Design a class cannonball to model a cannonball that is


Problem

Design a class Cannonball to model a cannonball that is fired into the air. A ball has

• An x- and a y-position.

• An x- and a y-velocity. Supply the following methods:

• A constructor with an x-position (the y-position is initially 0)

• A method move(double sec) that moves the ball to the next position (First compute the distance traveled in sec 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.)

• Methods get X and get Y that get the current location of the cannonball

• A method shoot 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 a time interval of 0.1 seconds until the y-position is 0; call get X and get Y after every move and display the position.) Use this class in a program that prompts the user for the starting angle and the initial velocity. Then call shoot.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Design a class cannonball to model a cannonball that is
Reference No:- TGS02630259

Expected delivery within 24 Hours