| 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: 2896
|
|
|
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: 24081
|
|
|
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]
|
 |
 |
|
|
subject: Could someone explain what is the error in this program?
|
|
|