Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Namespace ooptext
{
/// <Summary>
/// Simulate that both the dog and the frog are animals and use the facial image object idea to design them.
/// All Abstract: they are animals.
/// All have animal characteristics
/// </Summary>
Public class animal
{
Private int mood;
/// <Summary>
/// This attribute of an animal is used to determine the mood. It can be set by its Sub-object.
/// </Summary>
Public int mood
{
Get {return mood ;}
Set {mood = value ;}
}
Protected bool mammal = true; // whether it is a mammal
Static void main ()
{
Dog dog = new dog ();
Dog. Mood = 1;
Console. writeline (dog. sayhi ());
Frog frog = new frog ();
Frog. Mood = 2;
Console. writeline (frog. sayhi ());
Console. writeline (frog. islaysegg (true ));
Console. Readline ();
}
}
/// <Summary>
/// Use enumeration to describe the mood of an animal
/// </Summary>
Public Enum seek
{
Scared = 1, // good mood
Comforted = 2 // bad mood
}
Public class Dog: Animal
{
Public dog ()
{
// This member inherits the animal
This. mammal = true; // It is a mammal
}
Public String sayhi ()
{
Switch (mood)
{
// Note: this is an enumeration type. You also need to convert it to the int type to obtain the value.
// This is the details: Do not
Case (INT) Seek. Scared:
Return ("the dog is in a bad mood. Why !! ");
Case (INT) Seek. comforted:
Return ("the dog is in a good mood, Wangwang !! ");
}
Return ("the dog is in a bad mood. shake its tail !!! ");
}
}
Public class frog: Animal
{
Public Frog ()
{
This. mammal = false; // It is not a mammal
}
Public String sayhi ()
{
Switch (mood)
{
Case (INT) Seek. Scared:
Return ("the frog has a bad taste. I jumped into the river !!! ");
Case (INT) Seek. comforted:
Return ("The frog is in a good mood !!! ");
}
Return ("The frog is in a bad mood !!! ");
}
Public String islaysegg (bool Islay)
{
If (Islay)
{
Return ("the frog has to lay eggs ");
}
Else
{
Return ("the frog does not lay eggs !!! ");
}
}
}
}