I'm working on a CyberPet assignment and I'm not sure how to do the following:
'Then write an encounter ( CyberPet )
method that allows one CyberPet to encounter another and will describe the encounter by returning a String data type. Note that the method should take a CyberPet parameter. If a small pet encounters a big pet, the method should return, “See yah!” If a large pet encounters a small pet, the method should return, “I’m going to eat you!” If they are the same size, the method should return, “Let’s go to McDonalds!”
For example: if pet 1 is big and pet2 is small, the following method pet1.encounter( pet2 )
should return “I’m going to eat you.”'
Here's my code so far:
public class CyberPet
{
/*** Defaults/Constants ***/
public static final String DEFAULT_SIZE = "small";
public static final boolean DEFAULT_IS_EATING = false;
public static final boolean DEFAULT_IS_SLEEPING = false;
public static final boolean DEFAULT_IS_THINKING = true;
/*** Instance variables ***/
private String name;
private String size;
private boolean isEating;
private boolean isSleeping;
private boolean isThinking;
/*** Constructor Methods ***/
public CyberPet( String petName )
{
setName( petName );
size = DEFAULT_SIZE;
isEating = DEFAULT_IS_EATING;
isSleeping = DEFAULT_IS_SLEEPING;
isThinking = DEFAULT_IS_THINKING;
}
public CyberPet( String petName, String activity )
{
setName( petName );
size = DEFAULT_SIZE;
currentActivity( activity );
}
public CyberPet( String petName, String size, String activity )
{
setName( petName );
size = size;
currentActivity( activity );
}
/*** Transformer or Mutator Methods ***/
public void setName( String petName )
{
name = petName;
}
public void eat()
{
isEating = true;
isSleeping = false;
isThinking = false;
}
public void sleep()
{
isEating = false;
isSleeping = true;
isThinking = false;
}
public void think()
{
isEating = false;
isSleeping = false;
isThinking = true;
}
/*** Observor or Accessor Methods ***/
public String getState()
{
String state = "Error in state";
if ( isEating )
state = "Eating";
if ( isSleeping )
state = "Sleeping";
if ( isThinking )
state = "Thinking";
return state;
}
public String getName()
{
return name;
}
public String getSize()
{
return size;
}
/*** Helper methods ***/
public void currentActivity( String activity )
{
if ( activity == "eating" )
{
eat();
}
else if ( activity == "sleeping" )
{
sleep();
}
else
{
think();
}
}
public String encounter( CyberPet )
{
???
}
}
I don't even know how to go about creating the encounter method. This is just one of a number of things my professor decided to add on to the standard assignment from the textbook. How do I make two objects of the same type have the ability to interact before they're even instantiated (which they will be in the TestCyberPet class later)? I'm not looking to have someone write the method for me, just some ideas on how to go about doing this or where to look for more information that will help me. Any help would be greatly appreciated! Thanks in advance!