It's not a secret anymore!*
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 Android Security Essentials Live Lessons this week in the Android 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: 24183
    
  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]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Could someone explain what is the error in this program?
 
Similar Threads
Population and Growth Rate Problem
output
polymorphism
generic factory ?
Explain how it works so.