Answered step by step
Verified Expert Solution
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
Start Apache NetBeans
Create a new project called YourLastNameAssign with your actual last name.
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 initializedouble angle, double velocity, double height, double resistance sets up the initial conditions as follows:
The horizontal distance should be set to
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.cosMathtoRadiansangle
The vertical speed should be set to velocity multiplied by Math.sinMathtoRadiansangle
We will discuss the Math class in more detail when we get to Chapter For now, just use the expressions above and you should be fine.
public void updatedouble 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 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:
Calculate the new vertical speed by multiplying 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.
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.
Set the vertical speed to the result from step
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:
Displays a welcome message to the user.
Prompts for the launch angle in degrees.
Prompts for the initial velocity in meterssecond
Prompts for the initial height in meters.
Prompts for the time interval in seconds.
Prompts for the wind resistance.
Creates a Ball object.
Calls the initialize method on the Ball object using the first three values the user entered.
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.
Display the horizontal distance the ball travelled to the user.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started