Question: intro to java Programming Lab 12: Distance File Objective: To produce a formatted text file report showing distance travelled over time The distance a vehicle

intro to java

Programming Lab 12: Distance File

Objective: To produce a formatted text file report showing distance travelled over time

The distance a vehicle travels can be calculated as follows:

Distance = Speed * Time

For example, if a train travels 40 miles-per-hour for three hours, the distance traveled is 120 miles. Write a program that asks for the speed of a vehicle (in miles-per-hour) and the number of minutes it has traveled. It should use a loop to output the distance a vehicle has traveled for each time period specified by the user.

You must use at least one method in addition to main for this program. Don't use any class-level variables. Each variable should be declared inside a method.

Write the report to a file instead of the screen. Open the file in Notepad, pico, or another text editor to confirm the output.

Remember that the Unix command to display a text file is "cat", so that's how I displayed the file below. Notice the way the numbers line up vertically, and how results are rounded. Yours should do the same: Your program should input the total time in minutes, and also ask the user how many minutes should pass between each line of output. Input Validation: Do not accept a negative number for speed. The total number of minutes must be 60 or greater, and the number of minutes to pass between each output must be between 1 and the total number of minutes. Make sure to show the distance after the total time has passed, even if means that fewer minutes pass between the last two lines of output. Here is the sample output:

[cpersiko@fog cs111a]$ java DistanceFileExtra Enter the vehicle's speed in miles per hour: 100 Enter the number of minutes the vehicle was in motion: 180 How many minutes should be skipped between lines in the report? 30 Report written to DistanceReport.txt. [cpersiko@fog cs111a]$ cat DistanceReport.txt Minute Distance Traveled ---------------------------------- 30 50.0 60 100.0 90 150.0 120 200.0 150 250.0 180 300.0 [cpersiko@fog cs111a]$ java DistanceFileExtra Enter the vehicle's speed in miles per hour: 75 Enter the number of minutes the vehicle was in motion: 5 Enter 60 or greater for minutes: 95 How many minutes should be skipped between lines in the report? 100 Minutes skipped must be betwen 1 and 95: 15 Report written to DistanceReport.txt. [cpersiko@fog cs111a]$ cat DistanceReport.txt Minute Distance Traveled ---------------------------------- 15 18.8 30 37.5 45 56.3 60 75.0 75 93.8 90 112.5 95 118.8 [cpersiko@fog cs111a]$ java DistanceFileExtra Enter the vehicle's speed in miles per hour: -5 Enter 0 or greater for speed: -10 Enter 0 or greater for speed: 500 Enter the number of minutes the vehicle was in motion: 10 Enter 60 or greater for minutes: -10 Enter 60 or greater for minutes: 240 How many minutes should be skipped between lines in the report? 0 Minutes skipped must be between 1 and 240: 250 Minutes skipped must be between 1 and 240: 50 Report written to DistanceReport.txt. [cpersiko@fog cs111a]$ cat DistanceReport.txt Minute Distance Traveled ---------------------------------- 50 416.7 100 833.3 150 1,250.0 200 1,666.7 240 2,000.0 [cpersiko@fog cs111a]$ 

When you turn in your homework, make sure you turn in your Java source code, the screen output as a comment in your source code, and the file which your program produced - you can copy and paste the file output, clearly labeling it, so I can see all of this in one text file. Please show at least 2 sample outputs and files, as I did above.

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!