• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Could someone explain what is the error in this program?

 
bobby Varghese
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic