Instructions
We have previously completed the Travel.java program as well as the Waypoint class and Travelable interface. The source code to all of these is published in the Resources area here. Modify my versions of Waypoint (to make it public and Serializable) and Travelable (to make it public), but don't attach those results (I will just use my own copies).
In the chapter on File I/O (and my lectures) we discussed how to read and write objects through object input and output streams.
Modify the previous Travel.java program and save it as the new RouteApp.java program, but with the following changes:
Have your main method read in any previously saved route (if the route.ser file exists) using object I/O and then enter a main input loop to present a menu of choices to the user, as in the example near the end of the textbook chapter, but don't create a separate enum class to accomplish this (as in the example), just let the user choose to 1) add 2) change or 3) print the list of waypoints, or else just 4) exit the application.
If the user chooses 1, call an add method that does pretty much what the old Travel program did previously to create a list of waypoints, except this time make sure to store them as an array of waypoints (using our earlier work). Be able to hold at least 10 waypoints in the array (I won't test for more than this). When the user finishes entering data, the speed of the last waypoint should be zero (just like before - that's how you know to end the add mode) and your main loop should display the menu again. Note that if a previous list already existed (because either a route was read in from the route.ser file when the program started or because the user previously selected the menu add item while running the program during this session, just overwrite the previous list with the new one.
If the user chooses 2, call a change method that prompts them for the number of the waypoint to change, then lets them enter the new data (all four items) to replace the values in the old waypoint. After updating the route, present the main menu again. If the new waypoint has a speed of 0, delete all of the following waypoints in the list as this waypoint will now be the last waypoint in the route. If the waypoint that was previously the last one has its speed changed to a positive (non-zero) value, then after accepting the new data, immediately call the add method to continue building the remainder of the list.
If the user chooses 3, call a print method that prints the route as a numbered list of the waypoints in the route (using the toString method of class Waypoint) to the console. The numbering used in this list should start at 1 and this is also the number that should be used to identify which waypoint to change using the second menu item (above). The print option should conclude with the distance and time statistics as in the previous Travel program. Finally, the main loop should present the menu again.
If the user chooses 4, save each Waypoint in the array to a file called route.ser (overwriting any previous file) using Java Object I/O and then exit. Note, do not write the entire array as one object to the file. Each Waypoint element should be written seperately to the file.
Attach only the source code for RouteApp.java (make sure you spell and case the source code and data files correctly - don't send me any data files, however). I will compile and test your solution. It must compile for any credit (so watch your use of naming and casing to be sure they remain compatible with these specifications).