Results 1 to 6 of 6
  1. #1
    dorno83 is offline Member
    Join Date
    Nov 2008
    Posts
    7
    Rep Power
    0

    Default Error that i should know how to fix.

    Ok Im getting this dumb error and I think I have to initialize something just not quite sure how.
    Or maybe Im writing it wrong

    the error im getting is "variable tempStation might not have been initialized"

    I have the location of the error marked with a smiley face.
    Any help would be greatly appreciated.
    thanks
    dorno83



    /**
    * Locator - provides data for stations and zip code zones and methods
    * to access them.
    *
    * @author John Fulton
    * @author Ray Waite
    * @version 20080830
    */
    public class Locator
    {
    // array sizes (and limits)
    private final static int STATION_LIMIT = 100;
    private final static int POSTAL_ZONE_LIMIT = 100;

    // instance variables
    private Station [] stationArray;
    private PostalZone [] postalZoneArray;
    private int nextStation;
    private int nextPostalZone;

    /**
    * Constructor for objects of class Locator.
    */
    public Locator()
    {
    this.stationArray = new Station[STATION_LIMIT];
    this.postalZoneArray = new PostalZone[POSTAL_ZONE_LIMIT];
    nextStation = 0;
    nextPostalZone = 0;

    }

    /**
    * addStation - add a station to the array of stations.
    *
    * @param inputNumber int Station number to add
    * @param inputDescription String Station description to add
    * @param inputLocation String Location of station
    *
    * @return int index of added station, -1 if unable to
    * add (array already full)
    */
    public int addStation(int inputNumber, String inputDescription,
    Location inputLocation)
    {
    // replace with your code
    if (nextStation > 99)
    {
    return -1;
    }

    Station tempStation = new Station(inputNumber, inputDescription,
    inputLocation);

    stationArray[nextStation] = tempStation;

    return nextStation++;
    }

    /**
    * addStation - add a station to the array of stations.
    *
    * @param inputStation Station zipZone to be added
    * @return int index of added station, -1 if unable to
    * add (array already full)
    */
    public int addStation(Station inputStation)
    {
    // replace with your code
    if (nextStation > 99)
    {
    return -1;
    }

    :) Station tempStation = new Station(tempStation.getStationNumber(),
    tempStation.getDescription(), tempStation.getStationLocation());

    stationArray[nextStation] = tempStation;

    return nextStation++;
    }


    /**
    * addPostalZone - add a zip code zone to the array of PostalZones.
    *
    * @param inputZipCode int zip code of zipZone to add
    * @param inputLocation Location location object for zipZone to add
    *
    * @return int index of added zipZone, -1 if unable to
    * add (array already full)
    */
    public int addPostalZone(int inputZipCode, Location inputLocation)
    {
    //replace with your code
    if (nextPostalZone > 99)
    {
    return -1;
    }

    PostalZone tempPostalZone = new PostalZone(inputZipCode, inputLocation);

    postalZoneArray[nextPostalZone] = tempPostalZone;

    return nextPostalZone++;
    }

    /**
    * addPostalZone - add a zip code zone to the array of PostalZones.
    *
    * @param inputPostalZone PostalZone zipZone to be added
    *
    * @return int index of added zipZone, -1 if unable to
    * add (array already full)
    */
    public int addPostalZone(PostalZone inputPostalZone)
    {
    //replace with your code
    if (nextPostalZone > 99)
    {
    return -1;
    }

    PostalZone tempPostalZone = new PostalZone(tempPostalZone.getZipCode(),
    tempPostalZone.getZipLocation());

    postalZoneArray[nextPostalZone] = tempPostalZone;

    return nextPostalZone++;
    }


    /** postalZoneExists - indicates whether PostalZone exists.
    *
    * @param zipCode int zipCode of PostalZone to find
    *
    * @return boolean true is zipZone exists in zipArray,
    * false otherwise
    */
    public boolean postalZoneExists(int zipCode)
    {
    //replace with your code
    for (int i = 0; i < nextPostalZone; i++)
    {
    if (zipCode == postalZoneArray[i].getZipCode());
    {
    return true;
    }
    }

    return false;
    }

    /** findPostalZone - find and return PostalZone object.
    *
    * @param zipCode int zipCode of ZipZone to find
    *
    * @return ZipZone if found, returns zip zone object,
    * if not found, returns null reference
    */
    public PostalZone findPostalZone(int zipCode)
    {
    // replace with your code
    for (int i = 0; i < nextPostalZone; i++)
    {
    if (zipCode == postalZoneArray[i].getZipCode());
    {
    return postalZoneArray[i];
    }
    }

    return null;
    }


    /** toString - overrides method in base Object class.
    *
    * @return string values stationd in Station and PostalZone arrays,
    * formatted for printing
    */
    public String toString()
    {
    // replace with your code
    return "not correct";
    }


    }

  2. #2
    dorno83 is offline Member
    Join Date
    Nov 2008
    Posts
    7
    Rep Power
    0

    Default

    Anyone????

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  4. #4
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    As someone who is just learning I may well be on the wrong track but there is no tempStation in your declaration of variables that you have commented near the top of your code (instance variables)????

    Maybe?

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  6. #6
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    You are declaring a new tempStation, using the value of itself. The value of tempStation.getStationNumber() will need to come from somewhere else.

Similar Threads

  1. error 530 error authentication required
    By rgale in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 05-12-2008, 04:28 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
  •