Cannonball in java The Cannonball Class Design a class Cannonball to model a cannonball that is fired into the air. A ball has (instance variables) an x-position and a y-position. An x-velocity and a...




Cannonball in java
The Cannonball Class
Design a class
Cannonball
to model a cannonball that is fired into the air. A ball has (instance variables) an x-position and a y-position. An x-velocity and a y-velocity. A named constant for gravity (i.e., -9.81)


Supply the following methods: A constructor with an x-position and y-position parameters for the x-position and y-position instance variables. The x-velocity and y-velocity are initially 0. A helper (private) method
void move (double sec)
that moves the ball to the next position: Compute the distance travelled in sec seconds, using the current velocities Update the x-position and y-position Update the y-velocity by taking into account the gravitational acceleration of –9.81 m/s2 (the x-velocity is unchanged) A method
shoot
whose parameters are the angle α and initial velocity ν:


Compute the x-velocity as
ν * cos α
and the y-velocity as
ν * sin α
Keep calling
move
with a time interval of 0.1 seconds until the y-position is 0 After every move, display the position (i.e., x-position and y-position).
The Fire Cannonball (Client) Class (Program)
Define this class for use in the following client program
Fire Cannonball† that prompts the user for the starting angle and the initial velocity, creates a
Cannonball, and then shoots the
Cannonball
with the user input.
Import java.util.Scanner;public class Fire Cannonball{public static void main (String [] args)



{System.out.println ("Please enter a starting angle: "); Scanner in = new Scanner (System.in);double angle = in.nextDouble ();



System.out.println ("Please enter a firing velocity: ") double velocity = in.nextDouble ();Cannonball ball = new Cannonball (0.0, 0. Ball. Shoot (angle, velocity) ;}}
the methods
public static double Math. Cos (double angle)
and
public static double Math. Sin (double angle)
expect the given angle in
radians
(not degrees). You can use the method
public static double Math.toRadians (double angle)
to convert the angle from degrees to radians.



You are not allowed to modify the client program in any way.



Really need help with this I try some way but it still not work.






May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here