Results 1 to 2 of 2
  1. #1
    xx__rose is offline Member
    Join Date
    May 2010
    Posts
    6
    Rep Power
    0

    Default FileRead.java:79: cannot find symbol

    I'm writing a program that reads information from three seperate classes. Here is my code:

    Java Code:
    public class Animal
    {
       protected int id;
       protected String type;
       protected double mass;
     
        //------------------------------------------------------------------------
        //  Sets up an animal with the specified ID number, type and weight.
        //------------------------------------------------------------------------
     
       public Animal (int animalID, String animalType, double weight)
       {
          id = animalID;
          type = animalType;
          mass = weight;
       }
     
       //------------------------------------------------------------------------
       //  Returns information about this animal as a string.
       //------------------------------------------------------------------------
     
       public String toString()
       {
          String description = "ID: " + id + "\n";
     
          description += "Type: " + type + "\n";
          description += "Weight: " + mass + "\n"; 
     
          return description;  
       }
    }
    Java Code:
    public class Pet extends Animal
    {
       private String title;
       private String own;
     
       //------------------------------------------------------------------------
       //  Sets up a pet using the specified information.
       //------------------------------------------------------------------------
     
       public Pet (int animalID, String animalType, double weight, String name, String owner)
       {
          super (animalID, animalType, weight);
     
          title = name;
          own = owner;
       }
     
       //------------------------------------------------------------------------
       //  Returns information about this pet as a string.
       //------------------------------------------------------------------------
     
       public String toString()
       {
          String description = super.toString();
     
          description += "Name: " + title + "\n";
          description += "Owner: " + own + "\n"; 
     
          return description;  
       }
    }
    Java Code:
    public class ZooAnimal extends Animal
    {
       private int cage;
       private String train;
     
       //------------------------------------------------------------------------
       //  Sets up a zoo animal using the specified information.
       //------------------------------------------------------------------------
     
       public ZooAnimal (int animalID, String animalType, double weight, int cageNumber, String trainer)
       {
          super (animalID, animalType, weight);
     
          cage = cageNumber;
          train = trainer;
       }
     
       //------------------------------------------------------------------------
       //  Returns information about this zoo animal as a string.
       //------------------------------------------------------------------------
     
       public String toString()
       {
          String description = super.toString();
     
          description += "Cage: " + cage + "\n";
          description += "Trainer: " + train + "\n";
     
          return description;
       }
    }
    Java Code:
    import java.util.Scanner;
    import java.util.StringTokenizer;
    import java.io.*;
    
    public class FileRead
    {
       public static void main (String[] args) throws FileNotFoundException
       {
          Scanner scan = new Scanner(new File("animal.txt"));
          String animalType = null, name = null, trainer = null, owner = null, input = null;
          int animalID = 0, cageNumber = 0, animalTotal = 0, petTotal = 0, zooTotal = 0;
          double weight = 0.0;
          StringTokenizer st = null;
          Animal animal = null;
          Pet pet = null;
          ZooAnimal zooAnimal = null;
    
          System.out.println("\nThis program lists information from a series");
          System.out.println("of animals, pets and zoo animals from a seperate");
          System.out.println("text file. It prints theID number, animal type");
          System.out.println("and weight of each, if the animal is also a pet,");
          System.out.println("in addition. If the animal is a zoo animal, then");
          System.out.println("then a name and owner a cage number and trainer");
          System.out.println("will be added.\n");
    
          while (scan.hasNextLine())
          {
             input = scan.nextLine();
             st = new StringTokenizer(input, ",");
             animalID = Integer.parseInt(st.nextToken());
    	 animalType = st.nextToken();
             weight = Double.parseDouble(st.nextToken());		
    			
             if (animalID > 1000 && animalID < 3000)
             {
                animal = new Animal (animalID, animalType, weight);
                System.out.println(animal);
    	    animalTotal++;
             }
                if (animalID > 3000 && animalID < 8000)
                {
                   name = st.nextToken();
    	       owner = st.nextToken();
                   pet = new Pet(animalID, animalType, weight, name, owner);
                   System.out.println(pet);
    	       petTotal++;
                }
    	       if (animalID > 8000 && animalID < 10000)
                   {
                      cageNumber = Integer.parseInt(st.nextToken());
    	          trainer = st.nextToken();
                      zooAnimal = new ZooAnimal(animalID, animalType, weight, cageNumber, trainer);
                      System.out.println(zooAnimal);
    	          zooTotal++;
                   }
    	          if (animalID > 9999 && animalID < 1000)
    		  {
    		     System.out.println("The ID number is invalid.");
    		  }
          }
    
          System.out.println("\nNumber of animals total: " + animalTotal + ".");
          System.out.println("Number of pets total: " + petTotal + ".");
          System.out.println("Number of zoo animals total: " + zooTotal + ".");
    		
          FileWriter fw = new FileWriter("animalout.txt");
          BufferedWriter bw = new BufferedWriter(fw);
          PrintWriter pw = new PrintWriter(bw);
    
          pw.println(animal.createOutputFile());
          pw.close();
       }
    }
    The following code segment is animal.txt

    Java Code:
    1200,Ape,65.2,
    5000,Cow,600.8,Bessie,Stu DeFranco,
    7999,Dog,13.4,Arf,George Aycoth,
    8050,Giraffe,830.3,103,Samuel Trujillo,
    9700,Snake,23.0,239,Monica Trevizo,
    I'm trying to write the object's data type to the output file, "animalout.txt", but I keep getting an error reading:

    FileRead.java:79: cannot find symbol
    symbol : method createOutputFile()
    location: class Animal
    pw.println(animal.createOutputFile());

  2. #2
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    animal.createOutputFile() is the error

    Does the class animal have the method createOutputFile?

Similar Threads

  1. Java cannot find symbol- variable img
    By crutchfieldj in forum New To Java
    Replies: 3
    Last Post: 04-13-2010, 10:47 PM
  2. java:34:cannot find symbol
    By MissyMadi in forum New To Java
    Replies: 5
    Last Post: 11-09-2008, 06:53 PM
  3. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  4. Replies: 3
    Last Post: 05-01-2008, 08:30 AM
  5. [SOLVED] Java Error: Cannot find Symbol...
    By bobleny in forum New To Java
    Replies: 8
    Last Post: 04-15-2008, 06:35 AM

Posting Permissions

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