For example, if a vehicle travels 40 miles per hour for 3 hours, the distance traveled is 120 miles. Write a program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. It should then use a loop to display the total distance traveled at the end of each hour of that time period. Use a user input validation to enforce the user to enter a value for speed and travel distance that are greater than 0. Here is an example of the output:

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.4: A Case Study: Rectangular To Polar Coordinate Conversion
Problem 7E: (Simulation) Write a program to simulate the roll of two dice. If the total of the two dice is 7 or...
icon
Related questions
Question

Can you help me with this in Java?

The distance a vehicle travels can be calculated as follows:
distance = speed * time
For example, if a vehicle travels 40 miles per hour for 3 hours, the distance traveled is 120 miles.
Write a program that asks the user for the speed of a vehicle (in miles per hour) and how many
hours it has traveled. It should then use a loop to display the total distance traveled at the end of
each hour of that time period. Use a user input validation to enforce the user to enter a value for
speed and travel distance that are greater than 0.
Here is an example of the output:
What is the speed of the vehicle in mph? ®[Enter]
How many hours has it traveled? 0[Enter]
Invalid Speed value, Enter a value greater than zero: 40[Enter]
Invalid Hours value, Enter a value greater than zero: 4[Enter]
Hours
Miles Traveled
1
40
2
80
120
4
160
Transcribed Image Text:The distance a vehicle travels can be calculated as follows: distance = speed * time For example, if a vehicle travels 40 miles per hour for 3 hours, the distance traveled is 120 miles. Write a program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. It should then use a loop to display the total distance traveled at the end of each hour of that time period. Use a user input validation to enforce the user to enter a value for speed and travel distance that are greater than 0. Here is an example of the output: What is the speed of the vehicle in mph? ®[Enter] How many hours has it traveled? 0[Enter] Invalid Speed value, Enter a value greater than zero: 40[Enter] Invalid Hours value, Enter a value greater than zero: 4[Enter] Hours Miles Traveled 1 40 2 80 120 4 160
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Structured English
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,