Results 1 to 3 of 3
  1. #1
    c4l89 is offline Member
    Join Date
    Sep 2008
    Rep Power

    Default some help with this program?

    Hello everyone, I need some tips on how to get through this program.

    The program is here...

    The I-40 Highway Merchants Association wants to put electronic kiosks along interstate highway I-40 from Wilmington to San Diego. The kiosks will help travelers estimate travel time and distance. A traveler will be able to select a start city and a destination city along I-40, click Go, and the kiosk will display the road distance between the cities and the estimated travel time.

    Your task for this programming assignment is to create a prototype for the kiosk software. We have already written a graphical user interface, which is illustrated in the picture below (on a MacOS screen). You will have to write the backend code that provides the cities and the computed results.

    Protoype snapshot

    The user has 4 program controls: select the start city, select the destination city, click Go to get the computed results, and exit the program. The program exits when the user closes its window.

    The essential data for the program comes from a text file. The text file contains a series of records formatted as follows

    <A: name of city on I-40>
    <B: name of next city on I-40 to the east>
    <length of I-40 from A to B> <length of I-40 "bypass" around A><speed limit for I-40 between A to B>

    The length of the I-40 from A to B is the length from eastmost exit to A to westmost exit to B. The "bypass" length around A is the length of the highway from the eastmost exit to A to the westmost exit to A. You should assume that the speed limit on every bypass is 55 miles per hour.

    Here are two records from the text file.

    Needles, CA
    Kingman, AZ
    61 1 80
    Kingman, AZ
    Flagstaff, AZ
    128 4 80

    These two records indicate that:

    * Kingman, AZ is the first major city on I-40 that is east of Needles, CA, which is also on I-40.
    * The (bypass) part of I-40 going around Needles, CA is 1 mile long.
    * Traveling east, the last exit to Needles, CA is 61 miles from the first exit to Kingman, AZ. The speed limit on that stretch of road is 80 mph.
    * Flagstaff, AZ is the first major city on I-40 that is east of Kingman, AZ.
    * The bypass part of I-40 around Kingman, AZ is 4 miles long.
    * The distance on I-40 from Kingman, AZ to Flagstaff, AZ is 128 miles, and the speed limit it 80 mph.

    The picture below illustrates the two records. (The picture is not drawn to scale.)

    Needles to Flagstaff

    The text file is almost sorted with cities from west to east, but it may have several records out of place. We discuss how to deal with that problem in the implementation section below.

    Your program must consist of at least five different classes:

    * City
    * Highway
    * HighwayGUI. We are providing for you. Do not change it in any way!
    * TestCity
    * TestHighway

    The City and Highway classes serve as the "model" for the program while the HighwayGUI class provides the "view." TestCity and TestHighway are test cases .

    City should describe the records in the text file. That is, it should have instance variables for the name of the city, the name of the next city, the distances to the next city and around this city, and the speed limit on the highway to the next city. Most of the instance variables will require getter methods, but no setters.

    HighwayGUI uses the name of a text file, which is a command-line parameter, to create an instance of Highway.

    Your Highway class must define public methods that the HighwayGUI uses:

    * public Highway(String filename). A constructor with a String parameter. The actual parameter is the name of a text file with lines representing City records.
    * public String[] listOfCities(). Returns the list of names of major cities along the highway.
    * public String distanceBetween(String x, String y).
    Returns a String representing the distance between two cities named x and y (the last exit to x and the first exit to y). Reversing the two parameters should give the same result.
    * public String travelTime(String x, String y). Returns a String representing the travel time between two cities named x and y, assuming the traveler always drives the exact speed limit.

    Here are some sample return values for a Highway named h that is constructed using our completely ordered I-40 text file.
    x y h.distanceBetween(x,y) h.travelTime(x,y)
    "Needles, CA" "Flagstaff, AZ" 193 miles 2 hours 26 minutes
    "Needles, CA" "Needles, CA" 0 miles 0 minutes
    "Flagstaff, AZ" "Needles, CA" 193 miles 2 hours 26 minutes
    "Barstow, CA" "Wilmington, NC" 2560 miles 35 hours 41 minutes
    "Asheville, NC" "Tucumcari, TX" 1144 miles 16 hours 40 minutes


    The implementation of City is straightforward. Its instance variables should be private and initialized in the constructor.

    Highway must contain an array of City references ordered from west to east. You can assume there are no more than 200 cities. You may not use the ArrayList class or any other list classes provided by the Java API. All of the Highway instance variables should be private.

    The Highway class constructor must create the array from information a text file. The name of the text file is a parameter to the constructor. The Scanner lesson has instructions on how to read data from the text file. You are strongly urged to create a private method as follows:

    private void add(City x)

    add() inserts x into its proper position in the array. The way it works is as follows: scan the array looking for an element whose nextCity matches the name of City x. If you find one, insert x immediately after. If you don't find one, place x at the end of the array. The text file data is guaranteed to be arranged in such a way that using the add() method to put each City into the array creates an array that is sorted from west to east!

    Important: Write the constructor first. Test your code (with TestHighway) to make sure it is correct. Then proceed to the other methods.

    Here are three text files that you can use to test your constructor:

    * I-40cities.txt has all the cities in order from west to east.
    * out-of-order.txt has all the cities of the first file, but some are out of order.
    * tiny-road.txt has only 3 cities.

    To compute the total distance between two cities, add the city-to-city distances and the distances on all the bypasses around intermediate cities. The total distance does not include the bypass distances around the start or destination cities.

    To compute travel time, use the following techniques:

    * Keep all values as doubles for all arithmetic operations (add, subtract, multiply, divide). This will avoid initial, serious roundoff errors.
    * Do all initial computations in hours and fractions of hours.
    * If totalTime is the total time in hours and fractions of hours, then compute whole hours and whole minutes like this:
    o hours = (int) totalTime
    o minutes = (int) ((totalTime - hours) * 60)
    Ignore any fractions of minutes left over. (Do not round up.)

    Any tips would be great. Thanks!

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    Well, what do you have and what error/compiler messages does it produce? We are not simply going to do it for you.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power


    Yes, first of all try something yourself. If you stuck on something, we'll help you. I don't think anyone wants to help you in this way, and also I don't think anyone wants to read such a long post to help you.

Similar Threads

  1. Help with Program . . .
    By DSutta22 in forum New To Java
    Replies: 7
    Last Post: 09-18-2008, 07:47 AM
  2. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 08:24 AM
  3. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  4. cannot run the program
    By amiey in forum New To Java
    Replies: 1
    Last Post: 11-20-2007, 05:13 AM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts