1 Reply Latest reply: Jan 26, 2012 6:28 PM by EJP RSS

    Unsafe operations- Where am i messing up

    913537
      Trying to do this program for class and i keep getting the msg that I have unsafe or unchecked operations and i should rcomple with Xlint unchecked. Where is/are my mistake/s?






      import javax.swing.JOptionPane;
      import java.util.Scanner;
      import java.io.File;
      import java.io.IOException;
      import java.util.ArrayList;


      public class Mileage
      {
      public static void main(String[] args) throws IOException
      {
      String stateName, fileName, input, cityList, userInput, message, city;
      String response = "";
      int cityNum, j;
      int fromCity;
      int toCity;
      Scanner fileScan;

      fileName = JOptionPane.showInputDialog("Enter the name of the data file.");
      fileScan = new Scanner(new File(fileName));
      stateName = fileScan.nextLine();
      message = response + stateName + " Cities: /n/n";
      cityNum = fileScan.nextInt();
      ArrayList cities = new ArrayList(cityNum);
      int[][] mileage = new int[cityNum][cityNum];

      for (int i = 0; i < cityNum;)
      {
      fileScan.nextLine();
      city = fileScan.nextLine() + (i + 1) + ".";
      cities.add(city);

      for (j = 0; j < cityNum; j++);
      {
      mileage[i][j]= fileScan.nextInt();
      }
      }
      message = "Enter from and to cities for mileage, \"Quit\" or \"quit\" to quit.";
      input = JOptionPane.showInputDialog(message);

      while (input.equalsIgnoreCase("quit")== false)
      {
      fileScan = new Scanner(new File(input));
      toCity = fileScan.nextInt();
      fromCity = fileScan.nextInt();

      if (toCity < 1 )
      response = "Invalid values, try again.";
      else
      response = "It is " + mileage[fromCity][toCity] + " miles from " + cities.get(fromCity-1) + " to " + cities.get(toCity-1) + "./n/n";
      }
      }
      }

      Edited by: 910534 on Jan 26, 2012 4:02 PM