Structure of Database Files
As mentioned before, the database is stored in two different text files. One is only for route records, the other one is for route-time pair records. These two files will be input files to your program. (i.e. your program will read some data from both files)
Name of both input files will be entered by the user of your program. At the beginning of your program, user will be asked to enter an input file name for the route records. If the user enters a name for a file that does not exist, your program should display an appropriate message and ask for the name of a new input file name until the file is successfully opened. After the first input file is opened successfully, your program will ask for another input file name for time records file. The same file opening control check will be performed for this file too. If user enters a name for a file that does not exist, your program should display an appropriate message and ask for the name of a new input file name until the file is successfully opened.
Route Database File
The routes input file contains several information fields for each route. For a single route, there are three columns of information on the same line. Each line corresponds to the record of a route. The record structure for each route is described as follows:
Record line starts with a routeID. routeIDs are integer values and they are unique in each line. You will need to store this information to match the routes to times in the next file. It is followed by two strings: routeStart and routeEnd.
The abovementioned record structure, which contains 3 different data items in one line, is just for one route. The input file contains information about several routes. Therefore, there are several such records in the input file. You may assume there is a record in each line of input file, no line is empty. Also please note that the database file is not sorted (ordered).
Times Database File
The times database file contains time-route pairs written by that time. For a single time record, there are 2 pieces of information on the same line. The record structure for each route-time pair is described as follows:
- routeID is a single integer value.
- departureTime is a string value. It is in the format 00:00. (ex: 03:02, 16:45 etc.)
We assume that no time-route pair appears more than once in the Times database file. For example, if there is a pair such as Route11 Time1, then there will not be another pair such as Route11 Time1.
There is no specific order of records in both input files. That means you cannot assume that the records of the input files are ordered according to routeID, departureTime or any other data field.
The structure of the input files and the associated rules and assumptions explained above are fixed such that you cannot change them or make any other assumptions. You can assume that the input files will not be empty. You may examine the sample input files provided in the homework google folder for this homework. Please note that we have multiple input files for multiple scenarios, therefore your code should also work with all these possible outcomes.
Important! There might be any number of white spaces (i.e. blanks) and/or tabs between and after each data item in both files. You should handle it.
Database Search/Filter
Database search will basically be searching the routes database file for all routes after a given departure time. First you need to specify a Departure Location for your search. After entering departure location, (as long as it is not EXIT) you will be asked to enter a Departure Time to search for. You should only display the routes that are equal to or after this time. For example, if there are three bus routes from canakkale at times: 10:00, 12:00, 14:00 and the departure time is given as 12:00; then you should only print out the routes at 12:00 and 14:00 to the console.
Your results will contain all routes possible from the given departure location after (or equal to) the given departure time.
To do so, you must first search routes.txt and check each routeStart value to see if it is equal to the departure location given as input. If a match is found, you should store routeID and routeEnd. Then you should check times database file to check if there is a corresponding bus route with that stored routeID. If a record is found, then you should check the time on that record with the user input departure time. If the route time is later than or equal to the departure time, then you should display that search result on a separate line to the console as specified below. The format of this line is as follows:
- departureLocation is the users input,
- routeEnd is extracted from the routes database file, busTime is extracted from the times database file.
There is only one blank (white space) between each of these words. Please see the sample runs.
There will be any number of such lines, one for each route found, displayed on the console.
After successfully displaying one search result on console, your program will ask parameters for another search until EXIT word is entered as a termination command for departure location.
After a termination command, your program will close. You should check the Sample Runs below.
Sample Run
Below, we provide a sample run of the program that you will develop. The italic and bold phrases are inputs taken from the user. You should follow the input order in these examples and the prompts your program will display must be exactly the same as in the following examples.
Please enter a filename for route database: r cannot open routes database file
Please enter a filename for route database: routes cannot open routes database file
Please enter a filename for route database: routes.txt Please enter a filename for time database: time.txt cannot open times database file
Please enter a filename for time database: time cannot open times database file
Please enter a filename for time database: times.txt
Please enter departure location: Istanbul Please enter start time of travel: 03:45 The search results are:
Istanbul Ankara 12:00
Istanbul Izmir 15:00
Istanbul Trabzon 11:00
Istanbul Trabzon 07:15
Please enter departure location: Adana
Please enter start time of travel: aa:15
Time is not in correct format
Please enter start time of travel: :!A.E
Time is not in correct format
Please enter start time of travel: 34:60
Time is not in correct format
Please enter start time of travel: 20:80
Time is not in correct format
Please enter start time of travel: 29:01
Time is not in correct format
Please enter start time of travel: 1:15
Time is not in correct format
Please enter start time of travel: 01:15 The search results are:
Adana Ankara 19:00
Adana Ankara 23:45
Adana Ankara 22:00
Please enter departure location: Izmir Please enter start time of travel: 14:23 The search results are:
Izmir Istanbul 21:00
Izmir Istanbul 18:00
Izmir Istanbul 16:30
Please enter departure location: Trabzon
Please enter start time of travel: 23:00 The search results are:
Please enter departure location: Ankara Please enter start time of travel: 13:22 The search results are:
Ankara Adana 14:45
Ankara Adana 18:30
Ankara Istanbul 17:00
Ankara Istanbul 23:00
Ankara Gaziantep 22:45
Ankara Gaziantep 20:30
Please enter departure location: gaziantep Please enter start time of travel: 07:30 The search results are:
Please enter departure location: Antalya
Please enter start time of travel: 12:00 The search results are:
Please enter departure location: Eskisehir
Please enter start time of travel: 10:104
Time is not in correct format
Please enter start time of travel: 10:10 The search results are:
Eskisehir Ankara 17:30
Eskisehir Ankara 14:00
Please enter departure location: Izmir
Please enter start time of travel: 19:09
The search results are:
Izmir Istanbul 21:00
Please enter departure location: Gaziantep
Please enter start time of travel: 23:59 The search results are:
Please enter departure location: EXIT
Reviews
There are no reviews yet.