Question: I need help with the following Java program: Write a program that reads in a text file containing the step-by-step driving directions from one place

I need help with the following Java program:

Write a program that reads in a text file containing the step-by-step driving directions from one place to another, and prints the reverse directions (i.e., the directions from the destination back to the origin.) Additionally, it should compute the total round-trip distance and estimated fuel cost.

Create a project called Project2. Within this project, create a class called Directions. All of your code should be inside your main function in this one class.

File format

The file your program reads will have the following format:

 instructions Start at on ( miles) on ( miles) on ( miles) . . . is on the 

The first line gives the number of instructions. The "direction" entries can be either the words "right" or "left" (capitalized, or not) or the abbreviations "R" or "L".

An example file would be:

6 instructions Start at UMW Right on College Ave (0.9 miles) Left on Jefferson Davis Hwy (0.3 miles) R on Cowan Blvd (2.6 miles) R on Carl D Silver Pkwy (1.0 miles) Qdoba is on the Right

Output

Your program should print to the screen the reverse directions (in the same format) along with a summary statement as follows:

Start at Qdoba L on Carl D Silver Pkwy (1.0 miles) L on Cowan Blvd (2.6 miles) L on Jefferson Davis Hwy (0.3 miles) R on College Ave (0.9 miles) UMW is on the L Your 9.6-mile round trip will cost about $0.82.

Note that you are guaranteed that the file will be in this format. If it is not, it is an error on the file creator's part, and is not your fault.

Don't get lost!

Important: Stare hard at the above example and convince yourself that the program gave the correct answer. Note in particular that (1) you turn right on College Ave when you go to Qdoba, and also right on College Ave when you return. However, (2) you turn right on Cowan Blvd when you go to Qdoba, yet lefton Cowan Blvd when you return.

What I'm trying to point out is that simply reversing each street's direction and printing them in the opposite order is NOT the correct algorithm. I'm confident that you'll come up with the correct algorithm if you sit in a quiet room and stare at it for 20 minutes. Just like always, pictures will help, too.

User Input Information

Your program should ask the user for three pieces of important information:

The name of the input file that contains the "forwards" directions.

The current gas price, expressed as a decimal number (dollars per gallon.)

The approximate miles per gallon of the vehicle, expressed as a decimal number.

Example: if the directions are in a file called "Qdoba.txt", the current gas price is $2.40/gallon, and the user's vehicle gets 28 mpg, the user input will be:

Please enter the name of the text file: Qdoba.txt What is the price per gallon of gas? 2.4 What is your vehicle's fuel efficieny in miles per gallon? 28

Note on testing

Note that your program must work properly for any file in the format described above. You can use the above as a sample file, but you should of course alter this file and/or create your own so that you can robustly determine whether or not your program is functioning adequately.

qdoba.txtI need help with the following Java program: Write a program that

sugar_shack.txtreads in a text file containing the step-by-step driving directions from one

battlefield.txtplace to another, and prints the reverse directions (i.e., the directions from

carls.txtthe destination back to the origin.) Additionally, it should compute the total

Helpful String methods

Here are some methods in the String class that might be useful. You can find more information about these and more methods in the String class at the API page for the String class (Links to an external site.)Links to an external site..

boolean contains(String s) - returns true of string contains s

boolean equals(String s) - returns true if string equals s

int indexOf(String s [,fromIndex]) - returns index of s

String[] split(String s) - splits this string at instances of s

String substring(int begin) - returns substring from begin to length

String substring(int begin, int end) - returns substring from begin to end

String toLowerCase() - returns lowercase of string

String toUpperCase() - returns uppercase of string

qdoba.txt:

6 instructions

Start at UMW

Right on College Ave (0.9 miles)

Left on Jefferson Davis Hwy (0.3 miles)

R on Cowan Blvd (2.6 miles)

R on Carl D Silver Pkwy (1.0 miles)

Qdoba is on the Right

sugar_shack.txt:

4 instructions

Start at UMW

Left on College Ave (0.2 miles)

Left on William St (0.4 miles)

Sugar Shack is on the Left

battlefield.txt:

4 instructions

Start at UMW

Left on College Ave (0.4 miles)

Right on Hanover St (0.2 miles)

Battlefield Athletic Complex is on the Left

carls.txt

7 instructions

Start at UMW

Right on College Ave (0.5 miles)

R on Jefferson Davis Hwy (0.6 miles)

R on Fall Hill Ave (0.2 miles)

Left on Germania St (0.2 miles)

Right on Princess Anne St (0.1 miles)

Carls Ice Cream is on the Right

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!