473,416 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

FileRead.java:79: cannot find symbol

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

Expand|Select|Wrap|Line Numbers
  1. public class Animal
  2. {
  3.    protected int id;
  4.    protected String type;
  5.    protected double mass;
  6.  
  7.     //------------------------------------------------------------------------
  8.     //  Sets up an animal with the specified ID number, type and weight.
  9.     //------------------------------------------------------------------------
  10.  
  11.    public Animal (int animalID, String animalType, double weight)
  12.    {
  13.       id = animalID;
  14.       type = animalType;
  15.       mass = weight;
  16.    }
  17.  
  18.    //------------------------------------------------------------------------
  19.    //  Returns information about this animal as a string.
  20.    //------------------------------------------------------------------------
  21.  
  22.    public String toString()
  23.    {
  24.       String description = "ID: " + id + "\n";
  25.  
  26.       description += "Type: " + type + "\n";
  27.       description += "Weight: " + mass + "\n"; 
  28.  
  29.       return description;  
  30.    }
  31. }
  32.  
Expand|Select|Wrap|Line Numbers
  1. public class Pet extends Animal
  2. {
  3.    private String title;
  4.    private String own;
  5.  
  6.    //------------------------------------------------------------------------
  7.    //  Sets up a pet using the specified information.
  8.    //------------------------------------------------------------------------
  9.  
  10.    public Pet (int animalID, String animalType, double weight, String name, String owner)
  11.    {
  12.       super (animalID, animalType, weight);
  13.  
  14.       title = name;
  15.       own = owner;
  16.    }
  17.  
  18.    //------------------------------------------------------------------------
  19.    //  Returns information about this pet as a string.
  20.    //------------------------------------------------------------------------
  21.  
  22.    public String toString()
  23.    {
  24.       String description = super.toString();
  25.  
  26.       description += "Name: " + title + "\n";
  27.       description += "Owner: " + own + "\n"; 
  28.  
  29.       return description;  
  30.    }
  31. }
  32.  
Expand|Select|Wrap|Line Numbers
  1. public class ZooAnimal extends Animal
  2. {
  3.    private int cage;
  4.    private String train;
  5.  
  6.    //------------------------------------------------------------------------
  7.    //  Sets up a zoo animal using the specified information.
  8.    //------------------------------------------------------------------------
  9.  
  10.    public ZooAnimal (int animalID, String animalType, double weight, int cageNumber, String trainer)
  11.    {
  12.       super (animalID, animalType, weight);
  13.  
  14.       cage = cageNumber;
  15.       train = trainer;
  16.    }
  17.  
  18.    //------------------------------------------------------------------------
  19.    //  Returns information about this zoo animal as a string.
  20.    //------------------------------------------------------------------------
  21.  
  22.    public String toString()
  23.    {
  24.       String description = super.toString();
  25.  
  26.       description += "Cage: " + cage + "\n";
  27.       description += "Trainer: " + train + "\n";
  28.  
  29.       return description;
  30.    }
  31. }
  32.  
Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2. import java.util.StringTokenizer;
  3. import java.io.*;
  4.  
  5. public class FileRead
  6. {
  7.    public static void main (String[] args) throws FileNotFoundException
  8.    {
  9.       Scanner scan = new Scanner(new File("animal.txt"));
  10.       String animalType = null, name = null, trainer = null, owner = null, input = null;
  11.       int animalID = 0, cageNumber = 0, animalTotal = 0, petTotal = 0, zooTotal = 0;
  12.       double weight = 0.0;
  13.       StringTokenizer st = null;
  14.       Animal animal = null;
  15.       Pet pet = null;
  16.       ZooAnimal zooAnimal = null;
  17.  
  18.       System.out.println("\nThis program lists information from a series");
  19.       System.out.println("of animals, pets and zoo animals from a seperate");
  20.       System.out.println("text file. It prints theID number, animal type");
  21.       System.out.println("and weight of each, if the animal is also a pet,");
  22.       System.out.println("in addition. If the animal is a zoo animal, then");
  23.       System.out.println("then a name and owner a cage number and trainer");
  24.       System.out.println("will be added.\n");
  25.  
  26.       while (scan.hasNextLine())
  27.       {
  28.          input = scan.nextLine();
  29.          st = new StringTokenizer(input, ",");
  30.          animalID = Integer.parseInt(st.nextToken());
  31.      animalType = st.nextToken();
  32.          weight = Double.parseDouble(st.nextToken());        
  33.  
  34.          if (animalID > 1000 && animalID < 3000)
  35.          {
  36.             animal = new Animal (animalID, animalType, weight);
  37.             System.out.println(animal);
  38.         animalTotal++;
  39.          }
  40.             if (animalID > 3000 && animalID < 8000)
  41.             {
  42.                name = st.nextToken();
  43.            owner = st.nextToken();
  44.                pet = new Pet(animalID, animalType, weight, name, owner);
  45.                System.out.println(pet);
  46.            petTotal++;
  47.             }
  48.            if (animalID > 8000 && animalID < 10000)
  49.                {
  50.                   cageNumber = Integer.parseInt(st.nextToken());
  51.               trainer = st.nextToken();
  52.                   zooAnimal = new ZooAnimal(animalID, animalType, weight, cageNumber, trainer);
  53.                   System.out.println(zooAnimal);
  54.               zooTotal++;
  55.                }
  56.               if (animalID > 9999 && animalID < 1000)
  57.           {
  58.              System.out.println("The ID number is invalid.");
  59.           }
  60.       }
  61.  
  62.       System.out.println("\nNumber of animals total: " + animalTotal + ".");
  63.       System.out.println("Number of pets total: " + petTotal + ".");
  64.       System.out.println("Number of zoo animals total: " + zooTotal + ".");
  65.  
  66.       FileWriter fw = new FileWriter("animalout.txt");
  67.       BufferedWriter bw = new BufferedWriter(fw);
  68.       PrintWriter pw = new PrintWriter(bw);
  69.  
  70.       pw.println(animal.createOutputFile());
  71.       pw.close();
  72.    }
  73. }
  74.  
The following code segment is animal.txt

Expand|Select|Wrap|Line Numbers
  1. 1200,Ape,65.2,
  2. 5000,Cow,600.8,Bessie,Stu DeFranco,
  3. 7999,Dog,13.4,Arf,George Aycoth,
  4. 8050,Giraffe,830.3,103,Samuel Trujillo,
  5. 9700,Snake,23.0,239,Monica Trevizo,
  6.  
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());
May 8 '10 #1
1 2417
Dheeraj Joshi
1,123 Expert 1GB
Where is method createOutputFile is defined?

Regards
Dheeraj Joshi
May 9 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Bjorn Jensen | last post by:
Hi! An beginner question: Pleas help me with this (-: Error (the arrow points on the s in sqrt) ===== tal.java:6: cannot find symbol symbol : method sqrt(int) location: class tal...
1
by: Shiva48 | last post by:
Thanks to Gannon11 and ro351988- Moderator. I give below the complete Java file and pls help me to rectify the errors. package com.wrox.proj2ee.ch10.app; import java.io.*; import...
2
by: blkcygnus | last post by:
im trying to learn simple image processing-but i cant even get the thing to draw onscreen! heres the code import java.awt.*; import java.awt.geom.*; import java.awt.image.*; import...
1
by: jank | last post by:
hi, I wrote sending mass email program in java. If i try to compile using ant compiler, i am getting this error. c:\mail\src\com\mail\action\SendMail.java:125: cannot find symbol ...
4
by: jingchua | last post by:
Hi, can anyone help out here???? I have the below error after compling the file. Any idea what is wrong in the declaration that was done in the above code??? Appreciate any help on shedding some...
2
by: jazzyme2 | last post by:
New to Java. Working on this and ran into this problem. Any clues? java:42: cannot find symbol symbol : constructor Pay() location: class Pay Pay Emp1 = new Pay(); ^ 43:...
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
10
by: CodeNoob | last post by:
please help been working on a project got it down to 5 errors from 100 now i have no idea what to do. Errors: init: deps-jar: Created dir: C:\Users\Tommy\Desktop\build\classes Compiling 306...
2
suzee_q00
by: suzee_q00 | last post by:
Compiler seems to be hanging up on "new" but I know it isn't but I can't seem to figure out what it is that it doesn't like. Been chasing my tail for the last couple of days. Any help would be...
4
by: LadiPrather | last post by:
These error say there is not symbols, I have changed them some many times till I am lost. Please someone help. JOptionPane.showMessageDialog(null,"Oringinal Balance = $" + recieveAmount + ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.