Question: Week 1 1 1 . Review Section 5 . 1 0 in the book about files. 2 . Modify code you wrote for the Distance
Week
Review Section in the book about files.
Modify code you wrote for the Distance assignment # page according to the instructions in # on page
Submit
ModifiedDistanceDemo.java and txt file that was created.
Note:
Program template is attached.
To submit all files in one attempt you need to attach all files first and then click Submit. import java.io; Needed for PrintWriter and IOException
import java.util.Scanner; Needed for Scanner class
Chapter
Programming Challenge : Distance File
This program demonstrates the Distance class.
public class ModifiedDistanceDemo
public static void mainString args
throws IOException
String filename; File name
double speed; Vehicle's speed
int maxHours; Number of hours
int period; Counter for time periods
Create a Scanner object for keyboard input.
Scanner keyboard new ScannerSystemin;
Get the file name.
System.out.printThe distance report will be
"written to a file.
Enter the
"file name: ;
filename keyboard.nextLine;
Open the file; use PrintWriter class; name the PrintWriter class object outfile.
Get the speed.
System.out.printEnter the vehicle's speed: ;
speed keyboard.nextDouble;
Validate the speed.
while speed
Get the number of hours.
System.out.printEnter the number of hours the
"vehicle was in motion: ;
maxHours keyboard.nextInt;
Validate the hours.
while maxHours
Write the table header.
outFile.printlnHourtDistance Traveled";
outFile.println;
Write the table of distances.
period ;
while period maxHours
Create a Distance object for this period.
Distance d new Distancespeed period;
Write the distance for this period.
Increment period.
period;
Close the file.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
