Question: For this assignment you are going to write a program that simulates what happens when a ball is thrown at a particular angle and initial

For this assignment you are going to write a program that simulates what happens when a ball is thrown at a particular angle and initial velocity.

You will need to Make a class called Ball that keeps track of the status of the ball at a given time, and updates that status as time passes. In addition you must create a main class called YourlastnameAssign4.java (with your actual last name) that runs the simulation given input from the user.

Your Ball class should have the following private fields, all of which should be doubles:

  • hDist - the horizontal distance from the point where the ball was thrown in meters.
  • vDist - the vertical distance of the ball from the ground in meters.
  • hSpeed - how fast the ball is travelling horizontally in meters per second.
  • vSpeed - how fast the ball is travelling vertically in meters per second.

Your Ball class should also have the the following public methods:

public void initialize(double angle, double velocity, double height) - sets up the initial conditions as follows:

  • The horizontal distance should be set to 0.
  • The vertical distance should be set to height.
  • The horizontal speed should be set to velocity multiplied by Math.cos(Math.toRadians(angle)).
  • The vertical speed should be set to velocity multiplied by Math.sin(Math.toRadians(angle)).

Step by Step Solution

3.43 Rating (150 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Absolutely heres the code for the Ball class and the YourLastNameAssign4java class to simulate a ball thrown at an angle Balljava java public class Ba... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!