Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 . Start Apache NetBeans 2 . Create a new project called YourLastNameAssign 4 with your actual last name. 3 . create a class called

1. Start Apache NetBeans
2. Create a new project called YourLastNameAssign4 with your actual last name.
3. create a class called Ball that keeps track of the status of the ball at a given time, and updates that status as time passes. 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.
windResistance the rate of decrease in the horizontal speed due to wind resistance
Your Ball class should also have the following public methods:
public void initialize(double angle, double velocity, double height, double resistance)- sets up the initial conditions as follows:
The horizontal distance should be set to 0.
The vertical distance should be set to height.
The windResistance should be set to resistance
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)).
We will discuss the Math class in more detail when we get to Chapter 6. For now, just use the expressions above and you should be fine.
public void update(double time)- updates the status of the ball as follows:
The horizontal distance traveled in a given amount of time is calculated by multiplying the time by the horizontal speed. Take this value and add it to the horizontal distance.
Well assume wind resistance exists, so the horizontal speed will decrease over time. Its new value will be horizontal speed multiplied by (1- wind resistance).
The vertical distance and speed is a bit tricker because we have to factor in the effects of gravity. We can estimate this using the following algorithm:
1. Calculate the new vertical speed by multiplying 9.8(the acceleration due to gravity) by the time, and subtracting it from the old vertical speed. Store this in a local variable for now, because well need the old value for the next step.
2. Calculate the new vertical distance by averaging the old vertical speed and the new vertical speed, multiplying that by the time, and adding the result to the vertical distance.
3. Set the vertical speed to the result from step 1.
public double getHDist()- accessor method that returns the current horizontal distance.
public double getVDist()- accessor method that returns the current vertical distance.
In your main Java Class, write code in the main method that does the following:
2. Displays a welcome message to the user.
3. Prompts for the launch angle in degrees.
4. Prompts for the initial velocity in meters/second.
5. Prompts for the initial height in meters.
6. Prompts for the time interval in seconds.
7. Prompts for the wind resistance.
8. Creates a Ball object.
9. Calls the initialize method on the Ball object using the first three values the user entered.
10. Repeatedly call the update method on the Ball object using the time interval the user entered, as long as the ball is in the air (vertical distance is greater than zero.)
11. Display the horizontal distance the ball travelled to the user.

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

Optimization And Data Science Trends And Applications 5th Airoyoung Workshop And Airo Phd School 2021 Joint Event

Authors: Adriano Masone ,Veronica Dal Sasso ,Valentina Morandi

1st Edition

3030862887, 978-3030862886

Students also viewed these Databases questions

Question

WHAT IS AUTOMATION TESTING?

Answered: 1 week ago

Question

What is Selenium? What are the advantages of Selenium?

Answered: 1 week ago

Question

Explain the various collection policies in receivables management.

Answered: 1 week ago