Dmv.java:86:错误:找不到符号

时间:2016-02-27 07:25:18

标签: java variables symbols

import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Dmv
{
  private static void sort(Vehicle[] paramArrayOfVehicle)
  {
    for (int i = 0; i < paramArrayOfVehicle.length; i++) {
      for (int j = 0; j < paramArrayOfVehicle.length - 1; j++) {
        if ((paramArrayOfVehicle[j] != null) && ((paramArrayOfVehicle[(j + 1)] == null) || (paramArrayOfVehicle[j].getLicensePlate().compareTo(paramArrayOfVehicle[(j + 1)].getLicensePlate()) > 0)))
        {
          Vehicle localVehicle = paramArrayOfVehicle[j];
          paramArrayOfVehicle[j] = paramArrayOfVehicle[(j + 1)];
          paramArrayOfVehicle[(j + 1)] = localVehicle;
        }
      }
    }
  }




private static int findFree()
  {
    for (int i = 0; i < database.length; i++) {
      if (database[i] == null) {
        return i;
      }
    }
    return -1;
  }

  private static int findvehicle(String paramString)
  {
    paramString = paramString.toUpperCase();
    for (int i = 0; i < database.length; i++) {
      if ((database[i] != null) && (database[i].getLicensePlate().compareTo(paramString) == 0)) {
        return i;
      }
    }
    return -1;
  }

  private static Vehicle[] database = new Vehicle[100];
  private static int count = 0;

  public static void main(String[] paramArrayOfString)
  {
Scanner localScanner = new Scanner(System.in);
int i = -1;
while (i != 0)
{
  System.out.println("\nDMV Vehicle Database");
  System.out.println("0 Exit");
  System.out.println("1 List Vehicles");
  System.out.println("2 Display Vehicle Record");
  System.out.println("3 Add Vehicle");
  System.out.println("4 Remove Vehicle");
  System.out.println("5 Load Database from File");
  System.out.println("6 Save Database to File");
  System.out.print("Choice> ");

  i = localScanner.nextInt();
  localScanner.nextLine();
  String str2;
  Object localObject;
  switch (i)
  {
  case 1: 
    if (count > 0) {
      for (int j = 0; j < database.length; j++) {
        if (database[j] != null) {
          System.out.println(database[j]);
        }
      }
    } else {
      System.out.println("*** No Records In Database ***");
    }
    break;
  case 2: 
    System.out.print("Enter License Plate> ");
    String str1 = localScanner.nextLine();

    int m = findVehicle(str1);
    if (m < 0) {
      System.out.println("*** Plate " + str1 + " Not Found ***");
    } else {
      System.out.println(database[m]);
    }
    break;
  case 3: 
    int k = findFree();
    if (k < 0)
    {
      System.out.println("*** Database Full ****");
    }
    else
    {
      System.out.print("Enter License Plate> ");
      String str4 = localScanner.nextLine();
      System.out.print("Enter Owner> ");
      String str5 = localScanner.nextLine();
      System.out.print("Enter Phone Number> ");
      String str6 = localScanner.nextLine();

      database[k] = new Vehicle(str4, str5, str6);
      sort(database);

      count += 1;
    }
    break;
  case 4: 
    System.out.print("Enter License Plate> ");
    str2 = localScanner.nextLine();

    int n = findVehicle(str2);
    if (n < 0)
    {
      System.out.println("*** Plate " + str2 + " Not Found ***");
    }
    else
    {
      database[n] = null;

      count -= 1;
    }
    break;
  case 5: 
    try
    {
      System.out.print("Enter Filename> ");
      str2 = localScanner.nextLine();
      localObject = new ObjectInputStream(new FileInputStream(str2));
      for (int i1 = 0; i1 < database.length; i1++) {
        database[i1] = null;
      }
      count = 0;
      try
      {
        for (i1 = 0; i1 < database.length; i1++)
        {
          database[i1] = ((Vehicle)((ObjectInputStream)localObject).readObject());
          count += 1;
        }
      }
      catch (EOFException localEOFException) {}
      ((ObjectInputStream)localObject).close();
    }
    catch (Exception localException1)
    {
      System.out.println("*** File Error ***");
      System.out.println(localException1);
    }
  case 6: 
    try
    {
      System.out.print("Enter Filename> ");
      String str3 = localScanner.nextLine();
      localObject = new ObjectOutputStream(new FileOutputStream(str3));
      for (int i2 = 0; i2 < database.length; i2++) {
        if (database[i2] != null) {
          ((ObjectOutputStream)localObject).writeObject(database[i2]);
        }
      }
      ((ObjectOutputStream)localObject).close();
    }
    catch (Exception localException2)
    {
      System.out.println("*** File Error ***");
      System.out.println(localException2);
    }
  }
}

} }

以下是我收到的6个错误。我需要帮助。这是我为下周即将到期的最终项目所做的dmv计划。 JJJJJHJGHGHKJHKLJJJKLJLKLKLKLKJLKLKJKLLKJJLKLKKLLKJLK JLjLKjLKjJ kjKJ jj:Lj:L:Lj:LJ; J; JkhkgKXJBKJBkB kJ kJ kG K KJgKJKglfG G lG

Dmv.java:86: error: cannot find symbol
        int m = findVehicle(str1);
                ^
  symbol:   method findVehicle(String)
  location: class Dmv
Dmv.java:118: error: cannot find symbol
        int n = findVehicle(str2);
                ^
  symbol:   method findVehicle(String)
  location: class Dmv
Dmv.java:142: error: cannot find symbol
            for (i1 = 0; i1 < database.length; i1++)
                 ^
  symbol:   variable i1
  location: class Dmv
Dmv.java:142: error: cannot find symbol
            for (i1 = 0; i1 < database.length; i1++)
                         ^
  symbol:   variable i1
  location: class Dmv
Dmv.java:142: error: cannot find symbol
            for (i1 = 0; i1 < database.length; i1++)
                                               ^
  symbol:   variable i1
  location: class Dmv
Dmv.java:144: error: cannot find symbol
              database[i1] = ((Vehicle)         
 ((ObjectInputStream)localObject).readObject());
                       ^
  symbol:   variable i1
  location: class Dmv
6 errors

1 个答案:

答案 0 :(得分:0)

Dmv.java:86: error: cannot find symbol
        int m = findVehicle(str1);
                ^
  symbol:   method findVehicle(String)
  location: class Dmv
Dmv.java:118: error: cannot find symbol
        int n = findVehicle(str2);
                ^
  symbol:   method findVehicle(String)
  location: class Dmv

这是因为方法的名称是findvehicle而不是findVehicle。你必须解决这个问题。

Dmv.java:142: error: cannot find symbol
            for (i1 = 0; i1 < database.length; i1++)
                 ^
  symbol:   variable i1
  location: class Dmv
Dmv.java:142: error: cannot find symbol
            for (i1 = 0; i1 < database.length; i1++)
                         ^
  symbol:   variable i1
  location: class Dmv
Dmv.java:142: error: cannot find symbol
            for (i1 = 0; i1 < database.length; i1++)
                                               ^
  symbol:   variable i1
  location: class Dmv

此外,它应该是int i1中的for (i1 = 0; i1 < database.length; i1++)