Question
Do not use any data structures such as array or ArrayList to store data. The amount of time it takes an object to travel a
Do not use any data structures such as array or ArrayList to store data.
The amount of time it takes an object to travel a certain distance when traveling at a constant rate of speed is given by the formula t = d / r where d is the distance in meters and r is the rate of speed in kilometers per second.
Write java program that asks the user to enter the distance and the rate of speed, then calculates and prints the time.
Use a sentinel controlled or a flag controlled while loop to repeatedly accept the user input and calculate the result until the user choose not to.
Use if-else structure to valid the user inputs. You can combine two expressions using a logical operator (AND / OR). Print an error message if the inputs are invalid.
In the end, the average value is printed.
The results should be formatted appropriately.
Sample run:
Enter the distance in meters (-1 to exit): 150
Enter the rate of speed in kilometers per second: 40
Time: 3.75
Enter the distance in meters (-1 to exit): 200
Enter the rate of speed in kilometers per second: 35
Time: 5.71
Enter the distance in meters (-1 to exit): 100
Enter the rate of speed in kilometers per second: 30
Time: 3.33
Enter the distance in meters (-1 to exit): -1
Average: 4.27
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