Answer includes analysis, pseudocode and program. Analyze the following problem
ID: 3763162 • Letter: A
Question
Answer includes analysis, pseudocode and program. Analyze the following problem giving inputs, outputs and equations that connect the inputs to the outputs. Then write pseudocode for your algorithm. In your physics class you have a special pneumatic cannon that can fire a tennis hall. You need to fire the cannon at such an angle theta that the tennis ball will hit a second tennis ball being dropped from 100 meters away at a height of 75 meters. Assume that the initial velocity of the cannon ball is 50 m/s. It will have two velocities: an Xvel = 50cos theta and a Vvel=50sin theta. Write a program that will go through all the angles from 0 to 90 degrees. It will output the height y' that the cannon ball is at after travelling 100 meters in x. It will also calculate the height y' that the dropped tennis ball is at. Know also that the vertical velocity of the canon ball changes at 10 m/s^2 due to gravity. The tennis hall being dropped starts at a velocity of 0 m/s and increases at 10 m/s^2 due to gravity.Explanation / Answer
Answer:
Analysis of the problem:
a) Calculation of height of the cannon ball:
For the canon, the output height is,
In the horizontal direction,
Hence,
Therefore, the output height becomes as follows:
This is the output equation for canon ball.
b) Calculation of height of the tennis ball:
Formula for calculating the height of the tennis ball free falling from a certain height is given as,
Since it has to calculate the height of the ball at which it got hit will be calculated as,
The inputs here are the x-height of the cannon ball, y-height of tennis ball.
Program code to copy:
import java.text.DecimalFormat;
import java.util.Scanner;
public class CollisionsOfBalls
{
// main method
public static void main(String args[])
{
// declare the required variables
double tenBall = 0, canBall = 0;
double tenHeight = 0, canHeight = 0;
double theta = 0;
// create the objects for the DecimalFormat class and
// Scanner class
DecimalFormat form = new DecimalFormat("###.###");
Scanner in = new Scanner(System.in);
// prompt the user to enter the prompted values
System.out.print("Height of the tennis ball released: ");
tenBall = in.nextDouble();
System.out.print("Distance from which cannon ball fired: ");
canBall = in.nextDouble();
// formula to calculate the height of the balls and the
// angle
for (int i = 0; i < 90; i = i + 1)
{
theta = Math.toRadians(i);
canHeight = canBall * Math.tan(theta) - ((1 / 2) * (10) * Math.pow((canBall / (50 * Math.cos(theta))), 2.0));
tenHeight = 75 - ((1 / 2.0) * (10) * Math.pow((canBall / (50 * Math.cos(theta))), 2.0));
if (Math.ceil(tenHeight) == Math.floor(canHeight))
{
System.out.println("The angle at which the canon ball hits the tennis ball is: " + i);
System.out.println("The height of the tennis ball got hit by the"
+ " cannot ball is "+ form.format(tenHeight));
System.out.println("The height of the cannon ball hit the tennis ball after 100m is at:"
+ form.format(canHeight));
break;
}
}
}
}
Sample Output:
Height of the tennis ball released: 75
Distance from which cannon ball fired: 100
The angle at which the canon ball hits the tennis ball is: 12
The height of the tennis ball got hit by the cannot ball is 20.904
The height of the cannon ball hit the tennis ball after 100m is at:21.256