File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Could someone explain what is the error in this program? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Could someone explain what is the error in this program?" Watch "Could someone explain what is the error in this program?" New topic
Author

Could someone explain what is the error in this program?

bobby Varghese
Greenhorn

Joined: Feb 12, 2009
Posts: 6
public class Animal extends SimpleElement
{
public final static int MAMMAL = 1;
int animalClass;
String name, species, habitat, food, temperament;
FoodRecipe foodRecipe;
public void setName( String name )
{
this.name = name;
}
public String getName()
{
return name;
}
public void setSpecies( String species )
{
this.species = species ;
}
public String getSpecies()
{ return species;
}
public void setHabitat( String habitat )
{
this.habitat = habitat ;
}
public String getHabitat()
{
return habitat;
}
public void setFood( String food )
{
this.food = food ;
}
public String getFood()
{
return food;
}
public void setFoodRecipe( FoodRecipe recipe )
{
this.foodRecipe = recipe;
}
public FoodRecipe getFoodRecipe()
{
return foodRecipe;
}
public void setTemperament( String temperament )
{
this.temperament = temperament ;
}
public String getTemperament()
{
return temperament;
}
public void setAnimalClass( int animalClass )
{
this.animalClass = animalClass;
}
public int getAnimalClass()
{
return animalClass;
}
public void setAttributeValue( String name, String value )
{
if ( name.equals("class") && value.equals("mammal") )
setAnimalClass( MAMMAL );
else
throw new Error("No such attribute: "+name);
}
public String toString()
{
return name +"("+species+")";
}
}
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Have you complied this program? What compiler says? What's the error, If you post the error, then its easy for Ranchers to explain the cause of error . And Please use Code Tags


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Other than the fact that the classes SimpleElement and FoodRecipe aren't defined here (and they'd need to be for this code to compile) I don't see any outright errors.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Could someone explain what is the error in this program?