Question: Your assignment is to create a simple Java console program that accepts two input values from the user that will be used to calculate the

Your assignment is to create a simple Java console program that accepts two input values from the user that will be used to calculate the distance traveled by a falling object.

The formula for calculating the distance traveled by a falling object can be expressed as follows:

initial velocity of the object X time falling + (1/2) gravitational force X time2

The initial velocity of the object can be zero or greater and is measured in feet per second, including fractional numbers (e.g, 0, 9, or 10.4). The time falling is represented by a number of seconds that is greater than zero and may also be fractional (which may be expressed as 5, 7, or 22.68). The gravitational force value will use the value of force applied by the Earth, which is 32.17405 feet per second. The time is represented in seconds, and can also be expressed in fractional terms (12, 19, or 36.55 are valid input values).

The program you create should prompt the user to enter both the initial velocity of the falling object (as a number representing feet per second) and the time of the fall (as a number representing seconds). Once it accepts these input values, the program should output the distance traveled in feet, with that number displayed to a maximum of two decimal places. Below is a sample program output for reference:

Please enter the initial velocity of the falling object (in feet/second): 5.7 Please enter the time of the fall (in seconds): 34.8

Please enter the time of the fall (in seconds): 34.8 The distance traveled by an object falling at an initial velocity of 5.7 feet/second over a time of 34.8 seconds is 19680.39 feet.

Some tips and things to keep in mind:

  1. For this program, you will assume the user inputs numbers in the correct format for each of the two values requested; you do not have to check for input errors in this program.
  2. Gravitational force should be defined in your program as a named constant. You should follow the standards for setting this value (32.17405) as a constant variable in your program (please follow the example and conventions outlined in the Week 2 PowerPoint presentation (slide 15).
  3. You should use a Scanner object as shown in the Week 2 PowerPoint presentation and the code samples we reviewed to capture input from the user. Don't forget to add the necessary import statement to your file. A good walkthrough of using the Scanner can be found here: https://www.w3schools.com/java/java_user_input.asp (Links to an external site.)
  4. To perform the exponential calculation (time2), you can use the Math.pow function as described in the Week 2 presentation (slide 25).
  5. To convert the distance value into a number with a maximum of two decimal places, use the following formula as shown in the Tax Calculator program in the Week 2 PowerPoint: (int) (distance X 100) / 100.0.

I will test your program by putting in several input values and ensuring that your program produces output as specified above. Here are two more examples you can use to test your program before submission:

  1. initial velocity = 0, time = 34: distance = 18596.6
  2. initial velocity = 0.78, time = 122.9: distance = 243080.88

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!